標題:
陣列的長度
[打印本頁]
作者:
tonyh
時間:
2020-2-4 14:39
標題:
陣列的長度
利用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-2-4 14:54
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);
}
}
複製代碼
作者:
蘇行一
時間:
2020-2-4 14:54
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);
}
}
複製代碼
作者:
劉家銘
時間:
2020-2-4 14:55
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);
}
}
複製代碼
作者:
楊秉樺
時間:
2020-2-4 14:55
public class Ch37 {
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-2-4 14:55
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);
}
}
複製代碼
作者:
盧弘毅
時間:
2020-2-4 14:56
public class Ch50
{
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-2-4 14:57
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);
}
}
複製代碼
作者:
邱翊博
時間:
2020-2-4 14:58
package po;
public class po {
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-2-4 14:59
import java.util.Scanner;
public class Ch54 {
public static void main(String[] args) {
int t[]={1,2,3,4};
int n[][]={{1,2,3,4},{1,2,3,4},{1,2,3,4}};
int s[][][]={{{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(t.length);
System.out.println(n.length);
System.out.println(s.length);
}
}
複製代碼
作者:
沙芃妘
時間:
2020-2-4 15:00
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);
}
}
複製代碼
作者:
陳梓瑜
時間:
2020-2-4 15:03
public class Ch4 {
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.print(a.length);
System.out.println(b.length);
System.out.print(c.length);
}
}
複製代碼
作者:
黃煜城
時間:
2020-2-4 15:04
public class Ch20
{
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://istak.org.tw/seed/)
Powered by Discuz! 7.2