我如何将这个帕斯卡三角形变成正方形?

时间:2018-04-04 06:28:49

标签: java

我如何将这个帕斯卡三角形变成正方形?

import java.util.*;     
public class PascalSquare { 
    public static void main(String[] args) { 
    int row = 7;
    int[][] pascal  = new int[row +1][];
    pascal[1] = new int[1 + 2];
    pascal[1][1] = 1;


    for (int i = 2; i <= row; i++) {
        pascal[i] = new int[i + 2];
        for (int j = 1; j < pascal[i].length - 1; j++) {
            pascal[i][j] = pascal[i-1][j-1] + pascal[i-1][j];
        }
    }
    for (int i = 1; i <= row; i++) {
        for (int j = 1; j < pascal[i].length - 1; j++) {
            System.out.print(pascal[i][j] + " ");
        }
        System.out.println();
    }
}
}

//我希望这是一个7 * 7的方格,它遵循与pascal三角形相同的原则(添加上面的数字)

0 个答案:

没有答案