\r\n 换行
\t 缩进
正三角
打印展示
实现代码
1 2 3
| for (int i = 1; i < 10; i++) { for (int j = 1; j <= i; j++) System.out.print(j + " * " + i + " = " + (i * j) + (i == j ? "\r\n" : "\t")); }
|
倒三角
打印展示
实现代码
1 2 3
| for (int i = 9; i > 0; i--) { for (int j = 1; j <= i; j++) System.out.print(j + " * " + i + " = " + (i * j) + (i == j ? "\r\n" : "\t")); }
|
打印展示
代码实现
1 2 3
| for (int i = 1; i < 10; i++) { for (int j = i; j < 10; j++) System.out.print(i + " * " + j + " = " + (i * j) + (j == 9 ? "\r\n" : "\t")); }
|
正方形
打印展示
实现代码
1 2 3
| for (int i = 1; i < 10; i++) { for (int j = 1; j < 10; j++) System.out.print(i + " * " + j + " = " + (i * j) + (j == 9 ? "\r\n" : "\t")); }
|
倒方形
Math.min 获取两个数字中最小的数字
Math.max 获取两个数字中最大的数字
打印展示
实现代码
1 2 3
| for (int i = 9; i > 0; i--) { for (int j = 1; j < 10; j++) System.out.print(Math.min(i, j) + " * " + Math.max(i, j) + " = " + (i * j) + (j == 9 ? "\r\n" : "\t")); }
|