public static void main(String[] args){ System.out.println("N\t10*N\t100*N\t1000*N"); for(int i=1;i<=5;i++){ System.out.print(i+"\t"); for(int j=1;j<=3;j++){ int n = i; for(int k=1;k<=j;k++) n *= 10; System.out.print(n+"\t"); } System.out.println(); } }}
1 回答
已采纳
阿旭_
TA贡献217条经验 获得超353个赞
总共分两步:
步骤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++;
}
}
}
添加回答
举报
0/150
提交
取消
