static void YangHui(int row) {
int col = 2 * row - 1;/*行和列的关系*/
int[][] arr = new int[row][col];/*确定数组的长度*/
for (int i = 0; i < row; i++) {
for (int j = 0; j < col; j++) {
if (j == row + i || j == row - i)/*1出现的位置规律*/
arr[i][j - 1] = 1;
else {
int A, B;
if (i == 0) {/*判断上边界*/
A = 0;
B = 0;
} else if (j == 0) {/*判断左边界*/
A = 0;
B = arr[i - 1][j + 1];
} else if (j == col - 1) {/*判断右边界*/
A = arr[i - 1][j - 1];
B = 0;
} else {/*其他情况直接用通项*/
A = arr[i - 1][j - 1];
B = arr[i - 1][j + 1];
}
arr[i][j] = A + B;
}
}
}
for (int[] a : arr) {
for (int b : a) {
System.out.print((b == 0 ? " " : b) + "\t");
}
System.out.println();
}
}
10-25
261
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)