標題:
陣列的長度
[打印本頁]
作者:
陳品肇
時間:
2019-7-4 14:53
標題:
陣列的長度
利用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-7-4 15:10
package text369;
public class text123 {
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-7-4 15:10
public class nsez {
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-7-4 15:10
public class AAA
{
public static void main(String args[])
{
int s[]={1,2,3,4};
int a[][]={{1,2,3,4},{1,2,3,4},{1,2,3,4}};
int b[][][]={{{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(s.length);
System.out.println(a.length);
System.out.println(b.length);
}
}
複製代碼
作者:
湯東緯
時間:
2019-7-4 15:10
import java.util.Scanner;
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-7-4 15:11
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);
}
}
複製代碼
作者:
潘承渙
時間:
2019-7-4 15:11
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);
}
}
複製代碼
作者:
蔣宗儒
時間:
2019-7-4 15:11
public class junior01 {
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-7-4 15:11
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); //4
System.out.println(b.length); //3
System.out.println(c.length); //2
}
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/)
Powered by Discuz! 7.2