要想到二重数组来求解就很容易
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner reader=new Scanner(System.in);
int n=reader.nextInt();
int[][] yanghui=new int[n][n];
for (int i=0;i<n;i++){
yanghui[i][0]=1;
yanghui[i][i]=1;
for (int j=0;j<i;j++){
yanghui[i][j+1]=yanghui[i-1][j]+yanghui[i-1][j+1];
}
}
for (int i=0;i<n;i++){
for (int j=0;j<=i;j++){
System.out.print(yanghui[i][j]+" ");
}
System.out.println();
}
}
}