public static void main(String[] args) {
int[][] a = new int[6][];
//a[0][0] = 1;
for(int i=0;i<6;i++){
a[i]=new int[i+1];
}
for(int i = 0 ; i < 6 ; i++){
for(int j = 0 ; j <=i ; j++){
if(i == j || j == 0 || i ==0){
a[i][j] = 1;
continue;
}else {
a[i][j] = a[i-1][j-1]+a[i-1][j];
}
}
}
for (int m = 0; m < 6; m++) {
for (int n = 0; n <= m; n++) {
System.out.print(a[m][n]+" ");
}
System.out.print("\n");
}
}
}
时间: 2024-10-10 20:26:23