我就不吃芹菜

导航

 
 1         long rt[][] = new long[3][];
 2         rt[0] = new long[]{25, 76, 35};
 3         rt[1] = new long[]{90, 64, 13, 45, 9};
 4         rt[2] = new long[]{34, 67, 24, 81};
 5         
 6         for(int m = 0; m < 3; m++)                             //下标要定义成整数型的
 7         {
 8             for(int n = 0; n < rt[m].length; n++)
 9             {
10                 System.out.print(rt[m][n] + " ");
11             }
12             System.out.println();
13         }
14         
15         System.out.println();
16         
17         for(long re[]  : rt)                                              //没有下标,因为本身就是定义的数组
18         {
19             for(long rw : re)
20             {
21                 System.out.print(rw + " ");
22             }
23             System.out.println();
24         }

如果用foreach语句遍历二维数组,本身定义的变量的数据类型就是数组,所以不需要写上下标,而用for循环语句遍历二维数组,定义的必须是整数型数据,代表的是数组的下标。

记住数组顺序是从0开始的!!!

记住数组顺序是从0开始的!!!

记住数组顺序是从0开始的!!!

重要的事情说三遍!

posted on 2015-10-09 10:54  我就不吃芹菜  阅读(375)  评论(0编辑  收藏  举报