杨辉三角形简便代码

public class Demo {
	public static void main(String[] args) {
		int row=8;
		int colum=8;
		int[][] a=new int[row][colum];
		for(int i=0;i<row;i++)
		{
			for(int j=0;j<i;j++)
			{
				if(j==0||i==j)
					a[i][j]=1;
				else 
					a[i][j]=a[i-1][j]+a[i-1][j-1];
				System.out.print(a[i][j]+" ");
			}
			System.out.println();
		}
	}
}

  

猜你喜欢

转载自www.cnblogs.com/zdcn/p/9248709.html
今日推荐