杨辉三角

package lianxi;

public class Yanghuisanjiao {

    public static void main(String[] args) {
        int[][] ary =new int[10][10];
        for (int i = 0; i < 10; i++) 
        {
            for (int j = 0; j < 10-i; j++)
            {  

                System.out.print("  ");
            }

                 for (int k = 0; k < i+1; k++)
                 {
                    
                    if(k==0||k==i)
                    {
                        ary[i][k]=1;
                        System.out.print("  "+ary[i][k]+" ");
                        continue;
                    }
                    else
                    {
                       ary[i][k]=ary[i-1][k-1]+ary[i-1][k];
                       System.out.print("  "+ary[i][k]+" ");
                    }
                    
            }

            System.out.println();
        }    
            
        }

    }

posted @ 2016-05-20 20:53  凌零聆  阅读(217)  评论(0编辑  收藏  举报