返回列表 發帖

陣列 (一)

本帖最後由 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. }
複製代碼

  1. public class Ch34
  2. {
  3.     public static void main(String args[])
  4.     {
  5.       String a[]={"春","夏","秋","冬"};
  6.       String b[]=new String[]{"甲","乙","丙","丁"};
  7.       String c[];
  8.       c=new String[]{"東","南","西","北"};
  9.       System.out.print("陣列a: ");
  10.       for(int i=0; i<4; i++)
  11.          System.out.print(a[i]+" ");
  12.       System.out.println();   
  13.       System.out.print("陣列b: ");
  14.       for(int i=0; i<4; i++)
  15.          System.out.print(b[i]+" ");
  16.       System.out.println();
  17.       System.out.print("陣列c: ");
  18.       for(int i=0; i<4; i++)
  19.          System.out.print(c[i]+" ");
  20.     }
  21. }                              
複製代碼

TOP

  1. public class Ch26
  2. {
  3.     public static void main(String args[])
  4.     {
  5.         String a[]={"春","夏","秋","冬"};
  6.         String b[]={"甲","乙","丙","丁"};
  7.         String c[]={"東","西","南","北"};
  8.         System.out.print("陣列a: ");
  9.         for(int i=0; i<4; i++)
  10.             System.out.print(a[i]+" ");
  11.         System.out.println();
  12.         System.out.print("陣列b: ");
  13.         for(int i=0; i<4; i++)
  14.             System.out.print(b[i]+" ");
  15.         System.out.println();
  16.         System.out.print("陣列c: ");
  17.         for(int i=0; i<4; i++)
  18.             System.out.print(c[i]+" ");
  19.      }
  20. }
複製代碼

TOP

  1. public class Ch28
  2. {
  3.     public static void main(String args[])
  4.     {
  5.        String a[]=new String[]{"A","B","C","D"};
  6.        String b[]=new String[]{"A","B","C","D"};
  7.        String c[]=new String[]{"A","B","C","D"};
  8.       
  9.        System.out.println("陣列A:");
  10.        for(int i=0; i<4; i++)
  11.        {
  12.           System.out.println(a[i]);
  13.        }
  14.       
  15.        System.out.println("陣列B:");
  16.        for(int i=0; i<4; i++)
  17.        {
  18.           System.out.println(b[i]);
  19.        }
  20.       
  21.        System.out.println("陣列C:");
  22.        for(int i=0; i<4; i++)
  23.        {
  24.           System.out.println(c[i]);
  25.        }
  26.     }
  27. }
複製代碼

TOP

  1. public class Edit1
  2. {
  3.     public static void main(String args[])
  4.     {
  5.         String a[]={"春","夏","秋","冬"};
  6.         String b[]=new String[]{"a","b","c","d"};
  7.         String c[];
  8.         c[]=new String[]{"n","e","s","w"};
  9.         System.out.print("陣列a");
  10.         for(int i=0; i<4; i++)
  11.             System.out.print(a[i]+"");
  12.         System.out.println();
  13.         System.out.print("陣列b");
  14.         for(int i=0; i<4; i++)
  15.             System.out.print(b[i]+"");
  16.         System.out.println();
  17.         System.out.print("陣列c");
  18.         for(int i=0; i<4; i++)
  19.             System.out.print(c[i]+"");
  20.         System.out.println();
  21.     }
  22. }
複製代碼
我是眾神之王XXX  I love you
0000000000

TOP

返回列表