返回列表 發帖

陣列 (一)

本帖最後由 tonyh 於 2017-2-25 11:45 編輯

分別運用三種不同的陣列宣告方式, 完成參考執行畫面.

  1. public class Ch34
  2. {
  3.     public static void main(String args[])
  4.     {
  5.         String a[]={"春","夏","秋","冬"};
  6.         
  7.         String b[]=new String[]{"甲","乙","丙","丁"};

  8.         String c[];
  9.         c=new String[]{"東","南","西","北"};

  10.         System.out.print("陣列a: ");
  11.         for(int i=0; i<4; i++)
  12.             System.out.print(a[i]+" ");
  13.         System.out.println();

  14.         System.out.print("陣列b: ");
  15.         for(int i=0; i<4; i++)
  16.             System.out.print(b[i]+" ");
  17.         System.out.println();
  18.         
  19.         System.out.print("陣列c: ");
  20.         for(int i=0; i<4; i++)
  21.             System.out.print(c[i]+" ");
  22.         System.out.println();
  23.     }
  24. }
複製代碼

返回列表