/** * 打印杨辉三角形(帕斯卡三角形),打印10行 * */ public class Yanghuisanjiao { public static void main(String[] args) { int [][] a = new int[11][11]; for (int i = 0 ; i < 10 ; i++) { a[i][0] = 1; a[i][i] = 1; } for (int i = 1 ; 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 j = 0; j < 10-i;j++) { System.out.print(" "); } for (int k = 0; k < 10;k++) { if (a[i][k] != 0) { System.out.print(a[i][k]+" "); } } System.out.println(); } } }
本文出自 “橙子的成长记录” 博客,请务必保留此出处http://azhome.blog.51cto.com/9306775/1546776
原文:http://azhome.blog.51cto.com/9306775/1546776