public class Yanghui { public static void main(String[] args) { int[][] arr = new int[10][]; for (int i = 0; i < 10; i++) { arr[i] = new int[i + 1]; } //创建不规则二维数组 也可用规则的二维数组 for (int i = 0; i < 10; i++) { arr[i][0] = 1; arr[i][i] = 1; } //最外层赋值为1 for (int i = 2; i < 10; i++) { for (int j = 1; j < i; j++) { arr[i][j] = arr[i - 1][j] + arr[i - 1][j - 1]; } } //内层计算 for (int i = 0; i < 10; i++) { for (int k = 0; k < 10 - i; k++) { System.out.print(" "); } for (int j = 0; j <= i; j++) { System.out.print(arr[i][j] + " "); if (arr[i][j] < 10) System.out.print(" "); if (arr[i][j] < 100 && arr[i][j] >= 10) System.out.print(" "); } System.out.println(); } //调整代码间距,使其更加美观 } }