Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Java formating

  1. #1
    Join Date
    Dec 2012
    My Mood
    Thanked 0 Times in 0 Posts

    Default Java formating

    This is part of my code ( I can provide full if needed, just don't want to confuse people). So in my main method I declare a bunch of variables and in my printMessage method, I used the same name in the argument. Is this the correct way or should I change the name of the variable inside the argument to something else? Thanks

        public void printMessage(int startMiles1,int endMiles1 , int distance1, int gallons1, double milesGal1 )
        System.out.printf("%s","09 Acura TL");
        System.out.printf("%14d %14d %12d %12d %15.2f\n",startMiles1,endMiles1,distance1,gallons1,milesGal1);
        //Main method
        public static void main(String []args)
            int startMiles1 = 16923;
            int endMiles1 = 17283;
            int gallonsUsed1 = 18;    
            double pricePerGallon1 = 3.38;
            //New Object
            CarV5 car1 = new CarV5("09 Acura TL", endMiles1, startMiles1, gallonsUsed1, pricePerGallon1);
            car1.printMessage(startMiles1,endMiles1,distance1,gallonsUsed1, milesGal1);

  2. #2
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Thanked 619 Times in 561 Posts
    Blog Entries

    Default Re: Java formating

    Short answer? It doesn't matter. In each case the variable names should make sense in the context they're used. If they happen to have the same name, that's fine. If they don't, it's also just fine.

  3. The Following User Says Thank You to helloworld922 For This Useful Post:

    maple1100 (January 14th, 2013)

Similar Threads

  1. How to format text in java?
    By fourseven in forum Java Theory & Questions
    Replies: 3
    Last Post: May 16th, 2009, 09:42 PM