[蓝桥杯] 杨辉三角形

Scanner in = new Scanner(System.in);
int line = in.nextInt();
int[] arr = new int[line];
Arrays.fill(arr, 1);
for (int i = 0; i < line; i++) {
    for (int j = i - 1; j > 0; j--) {
        arr[j] += arr[j - 1];
    }
    for (int j = 0; j <= i; j++) {
        System.out.printf("%d ", arr[j]);
    }
    System.out.println();
}

发表评论