码迷,mamicode.com
首页 > 其他好文 > 详细

【程序33】

时间:2018-10-24 01:01:48      阅读:171      评论:0      收藏:0      [点我收藏+]

标签:rgs   ber   oid   class   out   new   要求   tle   keyword   

题目:打印出杨辉三角形(要求打印出10行如下图)

        1   

      1    1   

    1    2    1   

  1    3    3    1   

1    4    6    4    1   

1 5 10 10 5 1

…………


public class lianxi33 {

    public static void main(String[] args) {

        int[][] a = new int[10][10];

        for(int i=0; i<10; i++) {

            a[i][i] = 1;

            a[i][0] = 1;

        }

        for(int i=2; i<10; i++) {

            for(int j=1; j<i; j++) {

                a[i][j] = a[i-1][j-1] + a[i-1][j];

            }

        }

        for(int i=0; i<10; i++) {

            for(int k=0; k<2*(10-i)-1; k++) {

                System.out.print(" ");

            }

            for(int j=0; j<=i; j++) {

                System.out.print(a[i][j] + "   ");

            }

            System.out.println();

        }

    }

}

【程序33】

标签:rgs   ber   oid   class   out   new   要求   tle   keyword   

原文地址:https://www.cnblogs.com/yuyu666/p/9840206.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!