主题:不求最快但求最简(打印杨辉三角)
public static void printYangHui(int n){
int [][] a = new int [n][n];
for(int k=0;k<n;k++){
System.out.print(" ");
}
System.out.println("1");
for(int i=1;i<n;i++){
a[i][0] = a[i][i]=1;
for(int k=0;k<n-i;k++){
System.out.print(" ");
}
System.out.print(a[i][0]+" ");
for(int j=1;j<i;j++){
a[i][j] = a[i-1][j-1]+a[i-1][j];
System.out.print(a[i][j]+" ");
}
System.out.println(a[i][i]);
}
}
int [][] a = new int [n][n];
for(int k=0;k<n;k++){
System.out.print(" ");
}
System.out.println("1");
for(int i=1;i<n;i++){
a[i][0] = a[i][i]=1;
for(int k=0;k<n-i;k++){
System.out.print(" ");
}
System.out.print(a[i][0]+" ");
for(int j=1;j<i;j++){
a[i][j] = a[i-1][j-1]+a[i-1][j];
System.out.print(a[i][j]+" ");
}
System.out.println(a[i][i]);
}
}