I have the below code I need assistance with in formatting setwidths. The below
ID: 3565993 • Letter: I
Question
I have the below code I need assistance with in formatting setwidths. The below code "works" but it's not ideal formatting as it lacks consistency. Can somenone assist?
//print table heading lines
System.out.println("Month Account# Balance Account# Balance");
System.out.println("-------- -------- -------- -------- -------- ");
for(int month = 0; month <= 12; month++)
{
System.out.printf("%d %d %.2f %d %.2f %n",month,saver1.getAccountNumber(), saver1.getBalance(),
saver2.getAccountNumber(), saver2.getBalance());
Explanation / Answer
Try using -> to add tab.
public static void main(String aargs[]) {System.out.println("Month Account# Balance Account# Balance");
System.out.println("---------------------------------------- ");
for(int month = 0; month <= 12; month++)
{
System.out.printf("%d %d %.2f %d %.2f %n",month,saver1.getAccountNumber(), saver1.getBalance(), saver2.getAccountNumber(), saver2.getBalance());
}