总共分两步:
步骤1:将for中的第一个分号内容移到上面,第三个参数移到本for循环的最后一行。效果如下:public class Test86 {
public static void main(String[] args) {
System.out.println("N\t10*N\t100*N\t1000*N");
int i = 1;
for (; i <= 5;) {
System.out.print(i + "\t");
int j = 1;
for (; j <= 3;) {
int n = i;
int k = 1;
for (; k <= j;) {
n *= 10;
k++;
}
System.out.print(n + "\t");
j++;
}
System.out.println();
i++;
}
}
}
步骤2:将for(; ; )直接替换 while( )效果如下public class Test86 {
public static void main(String[] args) {
System.out.println("N\t10*N\t100*N\t1000*N");
int i = 1;
while (i <= 5) {
System.out.print(i + "\t");
int j = 1;
while (j <= 3) {
int n = i;
int k = 1;
while (k <= j) {
n *= 10;
k++;
}
System.out.print(n + "\t");
j++;
}
System.out.println();
i++;
}
}
}