public class Second { /* * 打印出杨辉三角形(要求打印出10行如下图) */ public static void main(String[] args){ int i,j,k; int[][] a=new int[10][10]; int n=10; for(i=0;i<n;i++) { for(j=0;j<=i;j++){ if(j==0||j==i) a[i][j]=1; else a[i][j]=a[i-1][j-1]+a[i-1][j]; } } for(i=0;i<n;i++){ for(k=0;k<=10-i;k++) System.out.print(" "); for(j=0;j<=i;j++){ System.out.print(a[i][j]); System.out.print(" "); } for(k=0;k<=10-i;k++) System.out.print(" "); System.out.print("\n"); } } }