Results 1 to 3 of 3
- 11-04-2011, 05:21 PM #1
Member
- Join Date
- Oct 2011
- Posts
- 13
- Rep Power
- 0
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
- 11-04-2011, 06:02 PM #2
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);
- 11-04-2011, 06:27 PM #3
Member
- Join Date
- Oct 2011
- Posts
- 13
- Rep Power
- 0
Similar Threads
-
Small problem with problem with Java, C++ parse program.
By dragstang86 in forum New To JavaReplies: 4Last Post: 10-30-2011, 03:43 AM -
Printf problem!!!
By pinar in forum New To JavaReplies: 3Last Post: 11-06-2010, 09:44 PM -
small problem
By rawan in forum Java AppletsReplies: 2Last Post: 04-07-2010, 03:32 AM -
small problem
By barusk in forum NetworkingReplies: 4Last Post: 03-21-2009, 06:19 AM -
Small problem
By ayoood in forum New To JavaReplies: 2Last Post: 06-06-2008, 12:27 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks