原文:java打印杨辉三角
源代码下载地址:http://www.zuidaima.com/share/1550463522032640.htm
java打印杨辉三角
package com.zuidaima.util; 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(); } }
运行后截图:
原文地址:http://blog.csdn.net/springmvc_springdata/article/details/41170571