应该是是这个图吧
- public static void main(String[] args) {
- Scanner sca = new Scanner(System.in);
- System.out.print("输入层数:");
- int n = sca.nextInt() + 1;
- int[][] a = new int[n][n];
- a = work(a, n - 1);
- for (int i = 0; i < n; i++) {
- for (int j = 0; j < i; j++) {
- System.out.print(a[i][j] + "\t");
- }
- System.out.println();
- }
- }
- public static int[][] work(int[][] a, int n) {
- a[n][0] = 1;
- for (int i = 1; i < n; i++) {
- a[n][i] = work(a, n - 1)[n - 1][i - 1] + work(a, n - 1)[n - 1][i];
- }
- return a;
- }
复制代码
|