標題:
陣列 (一)
[打印本頁]
作者:
鄭繼威
時間:
2022-12-3 10:03
標題:
陣列 (一)
本帖最後由 鄭繼威 於 2022-12-10 10:20 編輯
「陣列(Array)」
,按序排列的同類資料元素的
集合
。
1.
索引值是從0
開始計數
2.索引值
不可超出陣列的範圍
3.取陣列最後一個值=陣列長度-1
分別運用四種不同的陣列宣告方式, 完成參考執行畫面.
public class Ch34
{
public static void main(String args[])
{
String a[]={"春","夏","秋","冬"};
String b[]={"甲","乙","丙","丁"};
System.out.print("陣列a: ");
for(int i=0; i<4; i++)
System.out.print(a[i]+" ");
System.out.println();
System.out.print("陣列b: ");
for(int i=0; i<4; i++)
System.out.print(b[i]+" ");
System.out.println();
int c[]={1,2,3,4};
//string d[4]; -> c++宣告長度為4的空陣列
String d[]=new String[4]; //宣告長度為4的空陣列
d[0]="A";
d[1]="B";
d[2]="C";
d[3]="D";
//foreach
//for(陣列型態 變數:陣列(來源))
System.out.print("陣列c: ");
for(int i:c)
System.out.print(i+" ");
System.out.println();
System.out.print("陣列d: ");
for(String sa:d)
System.out.print(sa+" ");
System.out.println();
}
}
複製代碼
作者:
高昀昊
時間:
2022-12-3 11:29
public class Ch34
{
public static void main(String args[])
{
String a[]={"春","夏","秋","冬"};
String b[]={"甲","乙","丙","丁"};
System.out.print("陣列a: ");
for(String i:a)
System.out.print(i+" ");
System.out.println();
System.out.print("陣列b: ");
for(String i:b)
System.out.print(i+" ");
System.out.println();
int c[]={1,2,3,4};
String d[]=new String[4];
d[0]="A";
d[1]="B";
d[2]="C";
d[3]="D";
System.out.print("陣列c: ");
for(int i:c)
System.out.print(i+" ");
System.out.println();
System.out.print("陣列d: ");
for(String sa:d)
System.out.print(sa+" ");
System.out.println();
}
}
複製代碼
作者:
許宸瑀
時間:
2022-12-3 11:36
public class Ch01
{
public static void main(String args[])
{
String a[]={"春","夏","秋","冬"};
String b[]={"甲","乙","丙","丁"};
System.out.print("陣列a: ");
for(int i=0; i<4; i++)
System.out.print(a[i]+" ");
System.out.println();
System.out.print("陣列b: ");
for(int i=0; i<4; i++)
System.out.print(b[i]+" ");
System.out.println();
int c[]={1,2,3,4};
String d[]=new String[4];
d[0]="A";
d[1]="B";
d[2]="C";
d[3]="D";
System.out.print("陣列c: ");
for(int i:c)
System.out.print(i+" ");
System.out.println();
System.out.print("陣列d: ");
for(String sa:d)
System.out.print(sa+" ");
System.out.println();
}
}
複製代碼
作者:
曾善勤
時間:
2022-12-3 11:36
public class Ch01
{
public static void main(String args[])
{
string a[]={"春","夏","秋","冬"};
String b[]={"甲","乙","丙","丁"};
System.out.print("陣列a: ");
for(string e:a )
System.out.print(e+" ");
System.out.println();
System.out.print("陣列b: ");
for(string e:b)
System.out.print(e+" ");
System.out.println();
int c[]={1,2,3,4};
String d[]=new String[4];
d[0]="A";
d[1]="B";
d[2]="C";
d[3]="D";
System.out.print("陣列c: ");
for(int i:c)
System.out.print(i+" ");
System.out.println();
System.out.print("陣列d: ");
for(String s:d)
System.out.print(s+" ");
System.out.println();
}
複製代碼
作者:
許馹東
時間:
2022-12-3 11:37
public class ch011
{
public static void main(String args[])
{
String a[]={"春","夏","秋","冬"};
String b[]={"甲","乙","丙","丁","戊","己","庚","辛"};
System.out.print("陣列a: ");
for(int i=0; i<4; i++)
System.out.print(a[i]+" ");
System.out.println();
System.out.print("陣列b: ");
for(int i=0; i<8; i++)
System.out.print(b[i]+" ");
System.out.println();
int c[]={1,2,3,4};
String d[]=new String[4];
d[0]="A";
d[1]="B";
d[2]="C";
d[3]="D";
System.out.print("陣列c: ");
for(int i:c)
System.out.print(i+" ");
System.out.println();
System.out.print("陣列d: ");
for(String sa:d)
System.out.print(sa+" ");
System.out.println();
}
}
複製代碼
作者:
高鋐鈞
時間:
2022-12-3 11:39
public class Ch34
{
public static void main(String args[])
{
String x[]={"春","夏","秋","冬"};
String y[]={"甲","乙","丙","丁"};
System.out.print("陣列x: ");
for(String i:x)
System.out.print(i+" ");
System.out.println();
System.out.print("陣列y: ");
for(String i:y)
System.out.print(i+" ");
System.out.println();
int a[]={1,2,3,4};
String b[]=new String[4];
b[0]="A";
b[1]="B";
b[2]="C";
b[3]="D";
System.out.print("陣列a: ");
for(int i:a)
System.out.print(i+" ");
System.out.println();
System.out.print("陣列b: ");
for(String sa:b)
System.out.print(sa+" ");
System.out.println();
}
}
複製代碼
作者:
孫子傑
時間:
2022-12-3 11:40
本帖最後由 孫子傑 於 2022-12-3 11:43 編輯
public class Ch34
{
public static void main(String args[])
{
String a[]={"春","夏","秋","冬"};
String b[]={"甲","乙","丙","丁"};
System.out.print("陣列a: ");
for(String e:a)
System.out.print(e+" ");
System.out.println();
System.out.print("陣列a: ");
for(String e:b)
System.out.print(e+" ");
System.out.println();
int c[]={1,2,3,4};
String d[]=new String[4];
d[0]="a";
d[1]="b";
d[2]="c";
d[3]="d";
System.out.print("陣列c: ");
for(int e:c)
System.out.print(e+" ");
System.out.println();
System.out.print("陣列d: ");
for(String e:d)
System.out.print(e+" ");
System.out.println();
}
}
複製代碼
作者:
田家齊
時間:
2022-12-3 11:41
public class Ch29
{
public static void main(String args[])
{
String a[]={"春","夏","秋","冬"};
System.out.print("陣列a: ");
for(int i=0;i<4;i++)
System.out.println(a[i]);
System.out.println();
String b[]={"甲","乙","丙","丁"};
System.out.print("陣列b: ");
for(int y=0;y<4;y++)
System.out.println(b[y]);
System.out.println();
int c[]={1,2,3,4};
String d[]=new String[4];
d[0]="a";
d[1]="b";
d[2]="c";
d[3]="d";
System.out.print("陣列c: ");
for(int g:c)
System.out.println(g+" ");
System.out.println();
System.out.print("陣列d: ");
for(String h:d)
System.out.println(h+" ");
System.out.println();
}
}
複製代碼
作者:
利勁鋼
時間:
2022-12-5 19:46
public class Ch34
{
public static void main(String args[])
{
String x[]={"春","夏","秋","冬"};
String y[]={"甲","乙","丙","丁"};
System.out.print("陣列x: ");
for(String i:x)
System.out.print(i+" ");
System.out.println();
System.out.print("陣列y: ");
for(String i:y)
System.out.print(i+" ");
System.out.println();
int a[]={1,2,3,4};
String b[]=new String[4];
b[0]="A";
b[1]="B";
b[2]="C";
b[3]="D";
System.out.print("陣列a: ");
for(int i:a)
System.out.print(i+" ");
System.out.println();
System.out.print("陣列b: ");
for(String sa:b)
System.out.print(sa+" ");
System.out.println();
}
}
複製代碼
作者:
鍾易澄
時間:
2022-12-10 09:38
public class Ch01
{
public static void main(String args[])
{
String a[]={"春","夏","秋","冬"};
String b[]={"甲","乙","丙","丁"};
System.out.print("陣列a: ");
for(int i=0; i<4; i++)
System.out.print(a[i]+" ");
System.out.println();
System.out.print("陣列b: ");
for(int i=0; i<4; i++)
System.out.print(b[i]+" ");
System.out.println();
int c[]={1,2,3,4};
String d[]=new String[4];
d[0]="A";
d[1]="B";
d[2]="C";
d[3]="D";
System.out.print("陣列c: ");
for(int i:c)
System.out.print(i+" ");
System.out.println();
System.out.print("陣列d: ");
for(String sa:d)
System.out.print(sa+" ");
System.out.println();
}
}
複製代碼
作者:
郭博鈞
時間:
2022-12-10 09:42
public class Ch01
{
public static void main(String args[])
{
String a[]={"春","夏","秋","冬"};
String b[]={"甲","乙","丙","丁"};
System.out.print("陣列a: ");
for(int i=0; i<4; i++)
{
System.out.print(a[i]+" ");
System.out.println();
}
System.out.print("陣列b: ");
for(int i=0; i<4; i++)
{
System.out.print(b[i]+" ");
System.out.println();
}
int c[]={1,2,3,4};
String d[]=new String[4];
d[0]="A";
d[1]="B";
d[2]="C";
d[3]="D";
System.out.print("陣列c: ");
for(int i:c)
System.out.print(i+" ");
System.out.println();
System.out.print("陣列d: ");
for(String sa:d)
System.out.print(sa+" ");
System.out.println();
}
}
複製代碼
作者:
柳侑辰
時間:
2022-12-10 09:52
public class Ch03
{
public static void main(String args[])
{
String a[]={"春","夏","秋","冬"};
String b[]={"甲","乙","丙","丁"};
System.out.print("陣列a:");
for(int i=0;i<4;i++)
System.out.print(a[i]+" ");
System.out.println();
System.out.print("陣列b: ");
for(int i=0; i<4; i++)
System.out.print(b[i]+" ");
System.out.println();
int c[]={1,2,3,4};
String d[]=new String[4];
d[0]="A";
d[1]="B";
d[2]="C";
d[3]="D";
System.out.print("陣列c: ");
for(int i:c)
System.out.print(i+" ");
System.out.println();
System.out.print("陣列d: ");
for(String s:d)
System.out.print(s+" ");
System.out.println();
}
}
複製代碼
作者:
林紘憲
時間:
2022-12-10 09:58
public class Ch34
{
public static void main(String args[])
{
String a[]={"春","夏","秋","冬"};
String b[]={"甲","乙","丙","丁"};
System.out.print("陣列a: ");
for(int i=0; i<4; i++)
System.out.print(a[i]+" ");
System.out.println();
System.out.print("陣列b: ");
for(int i=0; i<4; i++)
System.out.print(b[i]+" ");
System.out.println();
int c[]={1,2,3,4};
String d[]=new String[4]; //宣告長度為4的空陣列
d[0]="A";
d[1]="B";
d[2]="C";
d[3]="D";
//foreach
//for(陣列型態 變數:陣列(來源))
System.out.print("陣列c: ");
for(int i:c)
System.out.print(i+" ");
System.out.println();
System.out.print("陣列d: ");
for(String sa:d)
System.out.print(sa+" ");
System.out.println();
}
}
複製代碼
作者:
李睿宸
時間:
2023-2-6 18:15
public class ch01
{
public static void main(String args[])
{
String a[]={"春","夏","秋","冬"};
String b[]={"甲","乙","丙","丁"};
System.out.print("陣列a: ");
for(String i:a)
System.out.print(i+" ");
System.out.println();
System.out.print("陣列b: ");
for(String i:b)
System.out.print(i+" ");
System.out.println();
int c[]={1,2,3,4};
String d[]=new String[4];
d[0]="A";
d[1]="B";
d[2]="C";
d[3]="D";
System.out.print("陣列c: ");
for(int i:c)
System.out.print(i+" ");
System.out.println();
System.out.print("陣列d: ");
for(String sa:d)
System.out.print(sa+" ");
System.out.println();
}
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2