输入一个正整数N,使得在杨辉三角序列中输出正整数N(使用java实现)
时间: 2023-03-12 16:15:43 浏览: 135
答案:
public class YangHuiTriangle {
public static void main(String[] args) {
int n = N;
int[][] arr = new int[n][n];
for (int i = 0; i < n; i++) {
for (int j = 0; j <= i; j++) {
if (i == j || j == 0) {
arr[i][j] = 1;
} else {
arr[i][j] = arr[i - 1][j - 1] + arr[i - 1][j];
}
System.out.print(arr[i][j] + " ");
}
System.out.println();
}
}
}
阅读全文