標題:
陣列的長度
[打印本頁]
作者:
tonyh
時間:
2014-7-12 14:29
標題:
陣列的長度
本帖最後由 tonyh 於 2014-7-12 15:12 編輯
利用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
}
}
複製代碼
作者:
張瀚仁
時間:
2014-7-12 15:00
public class ch37
{
public static void main(String args[])
{
int n[]={{90,85,85},
{70,75,80},
{80,95,80},
{70,95,75}};
int a[]{}=({5,5},{5,1},{1,5});
int b[][][]={{4},{5}}
System.out.println(n.length);
System.out.println(a.length);
System.out.println(b.length);
}
}
複製代碼
作者:
林以諾
時間:
2014-7-12 15:02
public class ch39
{
public static void main(String args[])
{
a[]={1,2,3,4};
a[][]={{1,2,3,4},{1,2,3,4},{1,2,3,4}};
a[][][]={{{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(n.length);
System.out.println(a.length);
System.out.println(b.length);
}
}
複製代碼
作者:
黃崇維
時間:
2014-7-15 18:11
public class ch37
{
public static void main(String args[])
{
int n[]={{90,85,85},
{70,75,80},
{80,95,80},
{70,95,75}};
int a[]{}=({5,5},{5,1},{1,5});
int b[][][]={{4},{5}}
System.out.println(n.length);
System.out.println(a.length);
System.out.println(b.length);
}
}
複製代碼
作者:
劉泳鱔
時間:
2014-7-15 18:12
public class ch37
{
public static void main(String args[])
{
int n[]={{90,85,85},
{70,75,80},
{80,95,80},
{70,95,75}};
int a[]{}=({5,5},{5,1},{1,5});
int b[][][]={{4},{5}}
System.out.println(n.length);
System.out.println(a.length);
System.out.println(b.length);
}
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/)
Powered by Discuz! 7.2