Reputation: 111
I am trying to print this loop into a table under N 10*N 100*N etc. I can get the loop to work but I can't figure out the spacing to move my values to the right. I am newer at this so any help would be appreciated.
package Exercises;
public class TabularOutput {
public static void main(String[] args)
{
//initialize variables
int w = 0;
int x = 0;
int y = 0;
int z = 0;
System.out.println("N 10*N 100*N 1000*N\n");
while(w<=4)
{
int a = w + 1;
System.out.println(a);
++w;
}
while(x<=4)
{
int b = (x + 1) * 10;
System.out.println(b);
++x;
}
while(y<=4)
{
int c = (y + 1) * 100;
System.out.println(c);
++y;
}
while(z<=4)
{
int d = (z + 1) * 1000;
System.out.println(d);
++z;
}
}//end method main
}//end class TabularOutput
Upvotes: 0
Views: 66
Reputation: 804
Try this:
int a=0, b=0, c=0, d=0;
while(w<=4)
{
a = w + 1;
System.out.print(a);
++w;
b = (x + 1) * 10;
System.out.print("\t"+b);
++x;
c = (y + 1) * 100;
System.out.print("\t"+c);
++y;
d = (z + 1) * 1000;
System.out.println("\t"+d);
++z;
}
Upvotes: 2