最好自己想,不要去参考网上的答案,纯找规律题
import java.util.Scanner;
public class B_06 {
public static void main(String[] args) {
int arr[][] = new int[34][34];
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
for (int i = 0; i < n; ++i) {
arr[i][0] = 1;
for (int j = 0; j < n; ++j) {
if (i == j)
arr[i][i] = 1;
}
}
for(int i=2; i<n; ++i){
for(int j=1; j<i; ++j){
arr[i][j] = arr[i-1][j-1]+arr[i-1][j];
}
}
for(int i=0; i<n; ++i)
{
for(int j=0; j<arr[i].length; j++){
if(arr[i][j]==0)
break;
if(j==0)
System.out.print(arr[i][j]);
else
System.out.print(" "+arr[i][j]);
}
System.out.println();
}
}
}