文章目录
for循环
public class MultiplyingChart {
public static void main(String args[]) {
int i, j;
for (i = 1; i <= 9; i++) {//从一循环到九
for (j = 1; j <= i; j++)//外层每1次循环里面就要循环i次i=1,j<=1, j 从1循环到 1 ; 输出 1*1 = 1i=2,j<=2,j从1 循环到 2 输出 1*2=1 2*2 =4
System.out.print(i + "*" + j + "=" + i * j + " ");
System.out.println();
}
}
}
while循环
public class MultiplyingChat2 {
public static void main(String args[]) {
int i = 1;
while (i <= 9) {
int j = 1;
while (j <= i) {
System.out.print(i + "*" + j + "=" + i * j + " ");
j++;
}
System.out.println();
i++;
}
}
}
do_while循环
public class MultplyingChart3 {
public static void main(String args[]) {
int i = 1;
do {
int j = 1;
do {
System.out.print(i + "*" + j + "=" + i * j + " ");
j++;
} while (j <= i);
System.out.println();
i++;
} while (i <= 9);
}
}
输出结果如下