本帖最後由 tonyh 於 2014-12-6 17:22 編輯
利用length屬性, 可取得陣列的長度, 即該陣列包含了幾位成員.- public class ch40
- {
- 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
- }
- }
複製代碼 |