標題:
陣列的長度
[打印本頁]
作者:
陳弘修
時間:
2020-12-12 10:03
標題:
陣列的長度
利用length屬性, 可取得陣列的長度, 即該陣列包含了幾位成員.
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}}};
上列三個陣列長度分別為何呢?
public class Ch41
{
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
}
}
複製代碼
作者:
龔品誠
時間:
2020-12-12 10:26
public class OwO
{
public static void main(String args[])
{
int x[]={1,2,3,4};
int y[][]={{1,2,3,4},{5,6,7,8},{9,10,11,12}};
int z[][][]={{{1,2,3,4},{5,6,7,8},{9,10,11,12}},{{13,14,15,16},{17,18,19,20},{21,22,23,24}}};
System.out.println(x.length);
System.out.println(y.length);
System.out.println(z.length);
}
}
複製代碼
作者:
張淯祺
時間:
2020-12-12 10:26
public class C4
{
public static void main(String args[])
{
int x[]={4,3,2,1};
int y[][]={{4,3,2,1},{4,3,2,1},{4,3,2,1}};
int z[][][]={{{4,3,2,1},{4,3,2,1},{4,3,2,1}},{{4,3,2,1},{4,3,2,1},{4,3,2,1}}};
System.out.println(x.length);
System.out.println(y.length);
System.out.println(z.length);
}
}
複製代碼
作者:
李穎俊
時間:
2020-12-12 10:27
public class hg
{
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);
System.out.println(b.length);
System.out.println(c.length);
}
}
複製代碼
作者:
朱閎聿
時間:
2020-12-12 10:28
public class a03
{
public static void main(String args[])
{
int x[]={1,2,3,4};
int y[][]={{1,2,3,4},{1,2,3,4},{1,2,3,4}};
int z[][][]={{{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(x.length);
System.out.println(y.length);
System.out.println(z.length);
}
}
複製代碼
作者:
陳莉榛
時間:
2020-12-12 10:29
public class Ch66
{
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);
System.out.println(b.length);
System.out.println(c.length);
}
}
複製代碼
作者:
林羿丞
時間:
2020-12-12 10:32
public class Ch666
{
public static void main(String args[])
{
int a[]={1,2,3,4};
int s[][]={{1,2,3,4},{1,2,3,4},{1,2,3,4}};
int d[][][]={{{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);
System.out.println(s.length);
System.out.println(d.length);
}
}
複製代碼
作者:
黃柏智
時間:
2020-12-12 10:37
public class A01
{
public static void main(String args[])
{
int a[]={1,2,3,4};
int b[][]={{1,2,3,4},{5,6,7,8},{9,10,11,12}};
int c[][][]={{{1,2,3,4},{5,6,7,8},{9,10,11,12}},
{{12,11,10,9},{8,7,6,5,},{4,3,2,1}}};
System.out.println(a.length);
System.out.println(b.length);
System.out.println(c.length);
}
}
複製代碼
作者:
王銘鴻
時間:
2020-12-19 09:11
public class Ch1
{
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);
System.out.println(b.length);
System.out.println(c.length);
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2