返回列表 發帖

陣列 (三) - 二維陣列

本帖最後由 tonyh 於 2014-7-5 14:51 編輯

一個 3x4 的二維陣列 可存放 12 筆資料
  1. public class ch35
  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. }
複製代碼

  1. public class ch35
  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+"]"+n"["+j+"]"+n[i][j]);
  11.               }
  12.          }
  13.     }
  14. }
複製代碼

TOP

  1. public class ch35
  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<4; 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. }
複製代碼

TOP

  1. public class ch37
  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. }
複製代碼

TOP

  1. public class ch37
  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. }
複製代碼

TOP

  1. public class ch35
  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. }
複製代碼

TOP

返回列表