需求:打印9*9乘法表
技术考核:
1.for嵌套循环
代码:
// 打印99乘法表
public static void print99Table() {
System.out.println("99乘法表");
System.out.print("\\" + " ");
for (int i = 1; i <= 9; i++) {
System.out.print(i + " ");
}
System.out.println();
for (int i = 1; i <= 9; i++) {
System.out.print(i + " ");
for (int j = 1; j <= 9; j++) {
if (j <= i) {
int value = i * j;
if (String.valueOf(value).length() >= 2) {
System.out.print(i * j + " ");
} else {
System.out.print(i * j + " ");
}
}
}
System.out.println();
}
}
效果图:

本文介绍了一种使用Java编程语言打印9*9乘法表的方法,通过嵌套for循环实现,详细展示了代码逻辑及运行效果。
8824

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



