import java.util.Scanner;
class Demo7 {
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入层数");
int n = sc.nextInt();
int[][] arr = new int[n][n];
for (int i = 0 ; i < n ;i++ ) {
arr[i][0] = 1;
arr[i][i] = 1;
}
for ( int i = 2;i < arr.length ;i++ ) {
for (int j =1;j <= n-1 ; j++) {
arr[i][j] = arr[i-1][j]+arr[i-1][j-1];
}
}
for ( int i=0;i<n ;i++ ) {
for (int j=0;j<n ;j++ ) {
if (arr[i][j]!=0) {
System.out.print(arr[i][j]+" ");
}
}
System.out.println();
}
}
} |