本帖最後由 tonyh 於 2012-11-3 16:46 編輯
利用length函數, 可算出陣列的長度, 即該陣列包含了幾位成員.- public class ch39
- {
- public static void main(String args[])
- {
- int a[]={1,2,3,4};
- int b[][]={{1,2,3,4},{1,2,3,4},{1,2,3,4}};
- int c[][][]={{{1,2,3,4},{1,2,3,4},{1,2,3,4}},{{1,2,3,4},{1,2,3,4},{1,2,3,4}}};
- System.out.println(a.length); //4
- System.out.println(b.length); //3
- System.out.println(c.length); //2
- }
- }
複製代碼 |