itmyhome2013-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(); } }
运行后截图:
由最代码官方编辑于2014-11-16 10:14:22
猜你喜欢
请下载代码后再发表评论


大兴西北 LV22020年12月13日
mengnan8989 LV222018年5月16日
773901419 LV12016年10月16日
terryang LV182014年1月2日
renwoaoxiangwxk LV12013年3月3日

2196316269 LV102月24日
华灯初上旧人安 LV52月19日
ITfans LV192020年12月29日
hejie19 LV22020年12月25日
大兴西北 LV22020年12月13日
1986hxc LV62020年12月9日
surprise LV12020年12月7日
w19991213 LV22020年9月21日
hfx15163406974 LV62020年9月21日
zzzz_fight LV22020年8月22日