JAVA基础编程之打印99乘法表
需求:打印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(); } }
效果图: