標題:
陣列的長度
[打印本頁]
作者:
tonyh
時間:
2012-11-3 16:42
標題:
陣列的長度
本帖最後由 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
}
}
複製代碼
作者:
t3742238
時間:
2012-11-3 16:45
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);
System.out.println(b.length);
System.out.println(c.length);
}
}
複製代碼
作者:
黃博鴻
時間:
2012-11-3 16:45
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);
System.out.println(c.length);
System.out.println(b.length);
}
}
複製代碼
作者:
劉漢文
時間:
2012-11-3 16:45
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);
System.out.println(b.length);
System.out.println(c.length);
}
}
複製代碼
作者:
t2364705
時間:
2012-11-3 16:46
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);
System.out.println(c.length);
System.out.println(b.length);
}
}
複製代碼
作者:
尤泓鈞
時間:
2012-11-3 16:47
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);
System.out.println(b.length);
System.out.println(c.length);
}
}
複製代碼
作者:
蔡昀佑
時間:
2012-11-3 16:48
public class ch38
{
public static void main(String args[])
{
int a[][][]={{{1,2,3},{4,5,6},{7,8,9}},
{{10,11,12},{13,14,15},{16,17,18}},
{{19,20,21},{22,23,24},{25,26,27}}};
for(int i=0; i<=2; i++)
{
for(int j=0; j<=2; j++)
{
for(int k=0; k<=2; k++)
{
System.out.println("a["+i+"]["+j+"]["+k+"]="+a[i][j][k]);
}
}
}
}
}
複製代碼
作者:
粘靖瑜
時間:
2012-11-3 16:51
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}};
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