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.


>> REGISTER NOW TO START POSTING


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

Results 1 to 3 of 3

Thread: justify output

  1. #1
    Member
    Join Date
    Dec 2010
    Posts
    69
    My Mood
    Busy
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default justify output

    I'm having an issue with justifying text output with printf(). So far I need the "sales" variable and "age" to be right justified, but just can't figure out to get it.

    				String name = nameTextField.getText();
    				String age = ageTextField.getText();
    				int sales =Integer.parseInt(salesTextField.getText());
                    nameTextField.setText("");
                    ageTextField.setText("");
                    salesTextField.setText("");
                    System.out.printf("  " + name + "                  " + age + "      " +  ef.format(sales) + "\n");
    I had the "ef.format" format the decimal places and need it to be aligned on the right side (lining up the decimals). Anybody know a solution?


  2. #2
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,676
    Thanks
    25
    Thanked 329 Times in 305 Posts

    Default Re: justify output

    Well printf is designed for formatting, I would probably use it accordingly. If you have ever used C, it works the same way.

    This should answer all of your printf questions (Using Java's printf( ) Method : printf MethodDevelopmentJava Tutorial)
    NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

    When asking for help, please follow these guidelines to receive better and more prompt help:
    1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
    2. Give full details of errors and provide us with as much information about the situation as possible.
    3. Give us an example of what the output should look like when done correctly.

    Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

  3. #3
    Member
    Join Date
    Dec 2010
    Posts
    69
    My Mood
    Busy
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: justify output

    Well I've found that link before, I just can't get anything to line up like this:

Similar Threads

  1. Help with output
    By jch02140 in forum What's Wrong With My Code?
    Replies: 6
    Last Post: January 8th, 2011, 01:09 PM
  2. what's the output?
    By dcshoecousa in forum Java Theory & Questions
    Replies: 3
    Last Post: November 27th, 2010, 11:11 AM
  3. Why am I getting this output?
    By ptabatt in forum What's Wrong With My Code?
    Replies: 5
    Last Post: August 6th, 2010, 07:36 PM
  4. need help with output.
    By VictorCampudoni in forum What's Wrong With My Code?
    Replies: 0
    Last Post: June 24th, 2010, 11:25 PM
  5. OutPut.
    By chronoz13 in forum Java Theory & Questions
    Replies: 3
    Last Post: August 29th, 2009, 10:54 AM