我正在练习用 Java 编写循环。这是我到目前为止所拥有的:
int a = 0;
int b = 0;
int c = 0;
int d = 0;
System.out.println ("Num "+"Square "+"Num "+"Square "+"Num "+"Square "+"Num "+"Square ");
for (int x = 1; x<=20; x++) {
a = x * 1;
b = 20+a;
c = 40+a;
d = 60+a;
for (int y = 1; y <= 1; y++) {
System.out.println (a + " " + (a * a) + " " + b + " " + (b * b) + " " + c +
" " + (c * c) + " " + d + " " + (d * d));
}
}
我根本不想更改代码(这意味着我不想添加比我已经拥有的更复杂的东西),但我希望列对齐。当数字开始以数字增加时,显然间距会变得混乱。有想法该怎么解决这个吗?
编辑:要回答您的问题,我对此很陌生,并且没有自学过更多。我非常确定有更好的方法可以做到这一点,但我只是在练习我的 for 循环。任何人,谢谢你的帮助。