本帖最後由 李泳霖 於 2021-2-3 17:03 編輯
分別運用四種不同的陣列宣告方式, 完成參考執行畫面.
a陣列放置:春夏秋冬
b陣列放置:甲乙丙丁
c陣列放置:1234
d陣列放置:ABCD- public class A
- {
- 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();
- }
- }
複製代碼 |