例3.5 利用不规则的二维数组存储数据,输出杨辉三角形
1 //杨辉三角形 2 public class ArrayYanghui 3 { 4 public static void main (String [] args) 5 { 6 int i, j; 7 int yanghui[] []= {{1}, {1,1}, {1, 2, 1}, {1, 3, 3, 1}, {1,4,6,4,1}}; 8 for (i = 0; i < yanghui.length - i; i++) 9 { 10 for (j = 0; j < yanghui.length - i; j++) 11 System.out.print(" "); 12 for (j = 0; j < yanghui [i].length; j++) 13 System.out.print (" "+yanghui [i] [j] + " "); 14 System.out.println ();} 15 System.out.println (); 16 } 17 }