標題:
陣列的長度
[打印本頁]
作者:
tonyh
時間:
2021-1-26 14: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
}
}
複製代碼
作者:
李柏穎
時間:
2021-1-26 14:13
public class Ch03
{
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);
}
}
複製代碼
作者:
吳聲寬
時間:
2021-1-26 14:15
public class Ch11
{
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);
}
}
複製代碼
作者:
王睿宇
時間:
2021-1-26 14:15
public class A01 {
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陣列的長度為: "+a.length);
System.out.println("b陣列的長度為: "+b.length);
System.out.println("c陣列的長度為: "+c.length);
}
}
複製代碼
作者:
楊澤全
時間:
2021-1-26 14:16
public class Ch05
{
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);
}
}
複製代碼
作者:
卓炘暘
時間:
2021-1-26 14:16
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[0].length);
System.out.println(c[0][0].length);
}
}
複製代碼
作者:
劉凱閔
時間:
2021-1-26 14:16
public class Ch09 {
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);
}
}
複製代碼
作者:
楊小萱
時間:
2021-1-26 14:17
public class Ch05
{
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);
}
}
複製代碼
作者:
王博裕
時間:
2021-1-26 14:18
public class Ch06 {
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);
}
}
複製代碼
作者:
藍健洲
時間:
2021-1-26 14:21
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},{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);
}
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2