我正在尝试将此循环打印到N 10 * N 100 * N等下的表中。我可以让循环工作但我无法弄清楚将值移到右边的间距。我是新手,所以任何帮助都会受到赞赏。
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
答案 0 :(得分:2)
试试这个:
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;
}