本帖最後由 tonyh 於 2012-10-20 16:51 編輯
6種不同的陣列宣告方式- public class ch35
- {
- public static void main(String args[])
- {
- String a[]={"春","夏","秋","冬"};
- System.out.println("陣列a: "+a[0]+a[1]+a[2]+a[3]);
-
- String[] b={"春","夏","秋","冬"};
- System.out.println("陣列b: "+b[0]+b[1]+b[2]+b[3]);
-
- String c[]=new String[]{"春","夏","秋","冬"};
- System.out.println("陣列c: "+c[0]+c[1]+c[2]+c[3]);
-
- String[] d=new String[]{"春","夏","秋","冬"};
- System.out.println("陣列d: "+d[0]+d[1]+d[2]+d[3]);
-
- String e[];
- e=new String[]{"春","夏","秋","冬"};
- System.out.println("陣列e: "+e[0]+e[1]+e[2]+e[3]);
-
- String[] f;
- f=new String[]{"春","夏","秋","冬"};
- System.out.println("陣列f: "+f[0]+f[1]+f[2]+f[3]);
- }
- }
複製代碼 |