標題:
陣列的長度
[打印本頁]
作者:
tonyh
時間:
2019-8-6 14:34
標題:
陣列的長度
利用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
}
}
複製代碼
作者:
曾暘竣
時間:
2019-8-6 14:40
public class Ch10
{
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);
}
}
複製代碼
作者:
余奕廷
時間:
2019-8-6 14:40
public class Ch01 {
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);
}
}
複製代碼
作者:
許育禎
時間:
2019-8-6 14:41
public class CH01
{
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}},{{13,14,15,16},{17,18,19,20},{21,22,23,24}}};
System.out.println(a.length);
System.out.println(b.length);
System.out.println(c.length);
}
}
複製代碼
作者:
許育慈
時間:
2019-8-6 14:41
public class Ch01
{
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}},
{{13,14,15,16},{17,18,19,20},{21,22,23,24}}};
System.out.println(a.length);
System.out.println(b.length);
System.out.println(c.length);
}
}
複製代碼
作者:
鄭宇崴
時間:
2019-8-6 14:41
本帖最後由 鄭宇崴 於 2019-8-6 14:44 編輯
public class Ch30
{
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}},{{13,14,15,16},{17,18,19,20},{21,22,23,24}}};
System.out.println(a.length);
System.out.println(b.length);
System.out.println(c.length);
}
}
複製代碼
作者:
黃永恩
時間:
2019-8-6 14:41
public class Ch02
{
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);
}
}
複製代碼
作者:
黃芊嬡
時間:
2019-8-6 14:42
import java.util.Scanner;
public class Ch01 {
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);
}
}
複製代碼
作者:
張嘉栩
時間:
2019-8-6 14:42
public class Ch10
{
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);
}
}
複製代碼
作者:
張郁庭
時間:
2019-8-6 14:43
public class Ch01
{
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);
}
}
複製代碼
作者:
莊鈞程
時間:
2019-8-6 14:43
import java.util.Scanner;
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);
System.out.println(b.length);
System.out.println(c.length);
}
}
複製代碼
作者:
張書涵
時間:
2019-8-6 14:43
public class Ch01{
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);
}
}
複製代碼
作者:
潘憶承
時間:
2019-8-6 14:45
public class Ch02
{
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);
}
}
複製代碼
作者:
葉俠愷
時間:
2019-8-6 14:46
import java.util.Scanner;
public class Ch11
{
public static void main(String args[])
{int a[]={1,2,3,4};
int b[][]={
{90,85,86},
{70,75,80},
{80,95,80},
{70,95,75},
{80,85,95}
};
int c[][][]=
{
{
{58,8,6,},{9,5,7},{9,8,5,},{9,8,2}
},
{
{5,4,5},{4,5,6},{7,5,4},{8,2,0}
},
{
{5,7,2},{5,7,0},{9,8,1},{8,2,0}
},
{
{5,4,2},{8,4,1},{4,7,3},{4,1,5}
}
};
System.out.println( a.length);
System.out.println( b.length);
System.out.println( c.length);
}
}
複製代碼
作者:
余映均
時間:
2019-8-6 14:46
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);
System.out.println(b.length);
System.out.println(c.length);
}
}
複製代碼
作者:
蔡明蓉
時間:
2019-8-6 14:46
public class Ch30 {
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