3.2.2多维数组 3.3 排序

例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 }
View Code

猜你喜欢

转载自www.cnblogs.com/allison-aichipingguo/p/10568287.html
3.3