嘿伙计们,我刚刚学会了如何进行嵌套循环。这就是我所做的。
public class TEst_1 {
public static void main(String[] args) {
final int max = 10;
for (int row = 1; row <= max; row++) {
for (int col = 1; col <= row; col++)
System.out.print(col);
System.out.println();
}
}
}
我打印了“col”以使每一行数到 10,我认为这非常好!
1
12
123
1234
12345
123456
1234567
12345678
123456789
12345678910
不过我有一个问题,我该如何反转数字?我的意思是从右边数列。
1
21
321
4321
54321
654321
7654321
87654321
987654321
10987654321
最佳答案
您可以在内部循环中反转计数:
for (int col = row; col > 0; col--)
关于java - 嵌套循环反转计数器位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12266784/