JAVA基础编程之打印99乘法表

时间:2024-11-11 08:34:32

需求:打印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基础编程之打印99乘法表