Board logo

標題: 陣列 (三) - 二維陣列 [打印本頁]

作者: tonyh    時間: 2016-5-13 20:01     標題: 陣列 (三) - 二維陣列

本帖最後由 tonyh 於 2017-11-25 15:20 編輯

一個 3x4 的二維陣列 可存放 12 筆資料

  1. public class Ch36
  2. {
  3.     public static void main(String args[])
  4.     {
  5.         int n[][]={{1,2,3,4},{5,6,7,8},{9,10,11,12}};
  6.         for(int i=0; i<3; i++)
  7.         {
  8.             for(int j=0; j<4; j++)
  9.                 System.out.println("n["+i+"]["+j+"]="+n[i][j]);
  10.         }
  11.     }
  12. }
複製代碼

作者: 曾挺桂    時間: 2016-5-13 20:31

  1. public class Ch36
  2. {
  3.     public static void main(String args[])
  4.     {
  5.         int n[3][4]={{1,2,3,4},{5,6,7,8},{9,10,11,12}};
  6.         for(int i=0; i<3; i++)
  7.         {
  8.             for(int j=0; j<4; j++)
  9.                 System.out.println("n["+i+"]["+j+"]="+n[i][j]);
  10.         }
  11.     }
  12. }
複製代碼

作者: 黃柏維    時間: 2016-5-13 20:31

  1. public class Ch36
  2. {
  3.     public static void main(String arg[])
  4.     {
  5.         int n[][]={{1,2,3,4},{5,6,7,8},{9,10,11,12}};
  6.         for(int i=0; i<3; i++)
  7.         {
  8.             for(int j=0; j<4; j++)
  9.                 System.out.println("n["+i+"]"+"["+j+"]="+n[i][j]);
  10.         }
  11.     }
  12. }
複製代碼

作者: 洪振庭    時間: 2016-5-13 20:32

  1. public class Ch37
  2. {
  3.     public static void main(String args[])
  4.     {
  5.         int a[][]={{1,2,3,4},{5,6,7,8},{9,10,11,12}};
  6.         System.out.print("陣列a: ");
  7.         for(int i=0; i<3; i++)
  8.         {
  9.           for(int j=0; j<4; j++)
  10.             System.out.println("a["+i+"]["+j+"]="+a[i][j]);
  11.         }
  12.     }
  13. }
複製代碼

作者: 李知易    時間: 2016-5-13 20:32

  1. public class Ch40
  2. {
  3.     public static void main(String args[]){
  4.         int b[][]={{1,2,3,4},{5,6,7,8},{9,10,11,12}};
  5.         for(int i=0;i<3;i++)
  6.             for(int j=0;j<4;j++)
  7.                 System.out.println("n["+i+"]["+j+"]="+b[i][j]);
  8.     }
  9. }
複製代碼

作者: 黃璽安    時間: 2016-5-13 20:33

  1. public class Ch40
  2. {
  3.     public static void main(String args[])
  4.     {
  5.         int n[][]={{1,2,3,4},{5,6,7,8},{9,10,11,12}};
  6.         for(int i=0; i<3; i++)
  7.         {
  8.             for(int j=0; j<4; j++)
  9.             {
  10.                 System.out.println("n["+i+"]["+j+"]="+n[i][j]);
  11.             }
  12.         }
  13.     }
  14. }
複製代碼

作者: 梁和雋    時間: 2016-5-13 20:35

  1. public class aa
  2. {
  3.     public static void main(String args[]){
  4.         int n[][]={{1,2,3,4},{5,6,7,8},{9,10,11,12}};
  5.         for(int i=0; i<3; i++){
  6.             for(int j=0; j<4; j++)
  7.                 System.out.println("n["+i+"]["+j+"]="+n[i][j]);
  8.         }
  9.     }
  10. }
複製代碼

作者: 王翔    時間: 2016-5-13 20:35

  1. public class Ch33
  2. {
  3.     public static void main(String args[])
  4.     {
  5.         int n[][]={{1,2,3,4},{5,6,7,8},{9,10,11,12}};
  6.         for(int i=0; i<3; i++)
  7.                 for(int j=0; j<4;j++)
  8.                         System.out.println("n"+"["+i+"]["+j+"]= "+n[i][j]);
  9.     }
  10. }
複製代碼

作者: 陳思惟    時間: 2016-5-13 20:36

  1. public class Ch40
  2. {
  3.     public static void main(String args[])
  4.     {
  5.         int n[][]={{1,2,3,4},{5,6,7,8},{9,10,11,12}};
  6.         for(int i=0; i<3; i++)
  7.         {
  8.             for(int j=0; j<4; j++)
  9.             {
  10.                 System.out.println("n["+i+"]["+j+"]="+n[i][j]);
  11.             }
  12.         }
  13.     }
  14. }
複製代碼





歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/) Powered by Discuz! 7.2