itmyhome的gravatar头像
itmyhome 2013-03-03 13:34:00

java打印杨辉三角

java打印杨辉三角

   public static void main(String[] args)
    {
        int i, j, n = 8, l, r;
        int a[] = new int[9];
        System.out.println(1);
        for (i = 1; i <= n; i++)
        {
            l = 1;
            System.out.print(1 + " ");
            for (j = 1; j <= i; j++)
            {
                r = a[j];
                a[j] = l + r; /* 每个数是上面两数之和 */
                l = r;
                System.out.print(a[j] + " ");
            }

            System.out.println();
        }
    }

运行后截图:

java打印杨辉三角


最代码官方编辑于2014-11-16 10:14:22


打赏

文件名:java打印杨辉三角.java,文件大小:0K 下载
最代码最近下载分享源代码列表最近下载
wuziayng1232  LV10 2022年11月14日
CaoCaii  LV6 2022年6月15日
明123456  LV11 2021年5月27日
大兴西北  LV2 2020年12月13日
mengnan8989  LV22 2018年5月16日
773901419  LV1 2016年10月16日
terryang  LV19 2014年1月2日
renwoaoxiangwxk  LV1 2013年3月3日
最代码最近浏览分享源代码列表最近浏览
try8023  LV18 1月16日
生米的  LV10 2023年3月3日
myBreaker  LV5 2023年1月11日
炫瓶百事可乐  LV1 2022年12月1日
wuziayng1232  LV10 2022年11月14日
CaoCaii  LV6 2022年6月15日
uni-code_0123  LV1 2022年6月12日
lwkjchen01 2022年5月7日
暂无贡献等级
mySong  LV11 2022年4月7日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友