package pers.redsoft.java.test.base;
/**
* 3种循环嵌套--九九乘法表
*
* @author redsoft
*
*/
public class Multiplication {
/**
* 主方法
*
* @param args
*/
public static void main(String[] args) {
System.out.println("============for==================");
for (int i = 1; i <= 9; i++) {
for (int j = 1; j <= i; j++) {
System.out.print(j + "*" + i + "=" + j * i + "\t");
}
System.out.println();
}
System.out.println("=============while=================");
int a = 1;
while (a <= 9) {
int b = 1;
while (b <= a) {
System.out.print(b + "*" + a + "=" + b * a + "\t");
b++;
}
a++;
System.out.println();
}
System.out.println("=============do while=================");
int c = 1;
do {
int d = 1;
do {
System.out.print(d + "*" + c + "=" + d * c + "\t");
d++;
} while (d <= c);
c++;
System.out.println();
} while (c <= 9);
}
}
Java的三种循环嵌套--九九乘法表
最新推荐文章于 2024-12-03 16:47:11 发布
本文介绍了一种使用Java编程语言实现九九乘法表的方法。通过三种不同的循环结构(for循环、while循环和do-while循环)展示了如何打印出完整的九九乘法表。这些示例有助于理解不同循环结构的应用场景。

3981

被折叠的 条评论
为什么被折叠?



