標題:
陣列 (一)
[打印本頁]
作者:
tonyh
時間:
2019-1-24 10:56
標題:
陣列 (一)
本帖最後由 tonyh 於 2019-1-24 11:04 編輯
分別運用四種不同的陣列宣告方式, 完成參考執行畫面.
public class Ch34
{
public static void main(String args[])
{
String a[]={"春","夏","秋","冬"};
String b[]=new String[]{"甲","乙","丙","丁"};
int c[];
c=new int[]{1,2,3,4};
String d[]=new String[4];
d[0]="A";
d[1]="B";
d[2]="C";
d[3]="D";
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();
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();
}
}
複製代碼
作者:
趙一鳴
時間:
2019-1-24 11:28
public class Ch04
{
public static void main(String[] args)
{
String a[]={"春","夏","秋","冬"};
String b[]=new String[]{"甲","乙","丙","丁"};
int c[];
c=new int[]{1,2,3,4};
String d[]=new String[4];
d[0]="A";
d[1]="B";
d[2]="C";
d[3]="D";
for(int i=0;i<4;i++)
System.out.print(a[i]+" ");
System.out.println();
for(int i=0;i<4;i++)
System.out.print(b[i]+" ");
System.out.println();
for(int i:c)
System.out.print(i+" ");
System.out.println();
for(String i:d)
System.out.print(i+" ");
System.out.println();
}
}
複製代碼
作者:
林育鋐
時間:
2019-1-24 11:32
public class Ch10 {
public static void main(String[] args) {
String a[]={"春","夏","秋","冬" };
String b[]={"甲","乙","丙","丁" };
int c[]={1,2,3,4};
String d[]={"A","B","C","D" };
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();
System.out.print("c陣列為 ");
for(int i=0;i<4;i++){
System.out.print (c[i]+" ");
}
System.out.println();
System.out.print("d陣列為 ");
for(int i=0;i<4;i++){
System.out.print (d[i]+" ");
}
}
}
複製代碼
作者:
孫焌仁
時間:
2019-1-24 11:33
public class Ch10
{
public static void main(String args[])
{
String a[]={"春","夏","秋","冬"};
String b[]=new String[]{"甲","乙","丙","丁"};
int c[];
c=new int[]{1,2,3,4};
String d[]=new String[4];
d[0]="A";
d[1]="B";
d[2]="C";
d[3]="D";
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();
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();
}
}
複製代碼
作者:
楊于暄
時間:
2019-1-24 11:33
public class Ch20
{
public static void main(String args[])
{
String a[]={"春","夏","秋","冬"};
String b[]=new String[]{"甲","乙","丙","丁"};
int c[];
c=new int[]{1,2,3,4};
String d[]=new String[4];
d[0]="A";
d[1]="B";
d[2]="C";
d[3]="D";
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();
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();
}
}
複製代碼
作者:
楊貳鈞
時間:
2019-1-24 11:46
public class Ch13
{
public static void main(String args[])
{
String a[]={"春","夏","秋","冬"};
String b[]=new String[]{"甲","乙","丙","丁"};
int c[];
c=new int[]{1,2,3,4};
String d[]=new String[4];
d[0]="A";
d[1]="B";
d[2]="C";
d[3]="D";
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();
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();
}
}
複製代碼
作者:
王騰立
時間:
2019-1-24 13:24
import java.util.Scanner;
public class Ch16
{
public static void main(String[] args)
{
String a[]={"春","夏","秋","冬"};
String b[]=new String[]{"甲","乙","丙","丁"};
int c[];
c=new int[]{1,2,3,4};
String d[]=new String[4];
d[0]="A";
d[1]="B";
d[2]="C";
d[3]="D";
System.out.println("陣列a:");
for(int i=0;i<4;i++)
System.out.print(a[i]+" ");
System.out.println();
System.out.println("陣列b:");
for(int i=0;i<4;i++)
System.out.print(b[i]+" ");
System.out.println();
System.out.println("陣列c:");
for(int i:c)
System.out.print(i+" ");
System.out.println();
System.out.println("陣列d: ");
for(String str:d)
System.out.print(str+" ");
System.out.println();
}
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2