Results 1 to 3 of 3
  1. #1
    Kaizer is offline Member
    Join Date
    Oct 2011
    Posts
    13
    Rep Power
    0

    Default Concerning a small output problem with PRINTF

    I have some basic code here, works fine, but I have an issue on the the display it outputs. I keep getting the first line (ie "1 1,050.00") one space behind all the next lines, as in misaligned. And I dont understand as my printf automatises the formatting of the text, presumably applying same settings to all )) Please help me ^^
    Thanks a lot for your time !
    K

    public class Interest {
    public static void main(String[]args) {
    double amount;
    double principal=1000.0;
    double rate=0.05;
    System.out.printf("%s%20s\n", "Year", "Amount on deposit");
    for (int year=1;year<=10;year++) {
    amount=principal*Math.pow(1.0+rate,year);
    System.out.printf("%4d%,20.2f\n ",year,amount);
    }
    }
    }
    Last edited by Kaizer; 11-04-2011 at 05:22 PM. Reason: needed more spaces between 1 and 1,050.00

  2. #2
    Shoss's Avatar
    Shoss is offline Member
    Join Date
    Feb 2011
    Posts
    94
    Rep Power
    0

    Default Re: Concerning a small output problem with PRINTF

    It took me longer than i'd like to admit to figure this out. Remove the extra space from the end of your formatting statement.

    Java Code:
    System.out.printf("%4d%,20.2f\n ",year,amount);
    
    to
    
    System.out.printf("%4d%,20.2f\n",year,amount);

  3. #3
    Kaizer is offline Member
    Join Date
    Oct 2011
    Posts
    13
    Rep Power
    0

    Default Re: Concerning a small output problem with PRINTF

    naha, excellent! thanks :p I have to admit I feel quite dumb .. xD

Similar Threads

  1. Small problem with problem with Java, C++ parse program.
    By dragstang86 in forum New To Java
    Replies: 4
    Last Post: 10-30-2011, 03:43 AM
  2. Printf problem!!!
    By pinar in forum New To Java
    Replies: 3
    Last Post: 11-06-2010, 09:44 PM
  3. small problem
    By rawan in forum Java Applets
    Replies: 2
    Last Post: 04-07-2010, 03:32 AM
  4. small problem
    By barusk in forum Networking
    Replies: 4
    Last Post: 03-21-2009, 06:19 AM
  5. Small problem
    By ayoood in forum New To Java
    Replies: 2
    Last Post: 06-06-2008, 12:27 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •