杨辉三角的源码:
1 import java.util.Scanner; 2 3 public class YangHui { 4 5 public static void main(String[] args) { 6 int i = 1; 7 Scanner mScanner = new Scanner(System.in); 8 int n = mScanner.nextInt(); 9 int yh[] = new int[n]; 10 for (i = 0; i < yh.length; i++) { 11 yh[i] = 1; 12 for (int j = i - 1; j > 0; j--) { 13 yh[j] = yh[j - 1] + yh[j]; 14 } 15 for (int j = 0; j <= i; j++) { 16 System.out.print(yh[j] + "\t"); 17 } 18 System.out.println(); 19 } 20 } 21 22 }
-
原文:http://www.cnblogs.com/zhjsll/p/4374484.html