返回列表 發帖

陣列 (四) - 三維陣列

本帖最後由 tonyh 於 2019-1-24 11:24 編輯

一個 2x3x4 的三維陣列 可存放 24 筆資料

  1. //2x3x4
  2. public class Ch37
  3. {
  4.     public static void main(String args[])
  5.     {
  6.         int n[][][]={{{1,2,3,4},{5,6,7,8},{9,10,11,12}},
  7.                      {{13,14,15,16},{17,18,19,20},{21,22,23,24}}};
  8.         for(int i=0; i<2; i++)
  9.         {
  10.             for(int j=0; j<3; j++)
  11.             {
  12.                 for(int k=0; k<4; k++)
  13.                     System.out.println("n["+i+"]["+j+"]["+k+"]="+n[i][j][k]);
  14.             }
  15.         }
  16.     }
  17. }
複製代碼

  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.                      {{13,14,15,16},{17,18,19,20},{21,22,23,24}}};
  7.         for(int i=0; i<2; i++)
  8.         {
  9.             for(int j=0; j<3; j++)
  10.             {
  11.                 for(int k=0; k<4; k++)
  12.                     System.out.println("n["+i+"]["+j+"]["+k+"]="+n[i][j][k]);
  13.             }
  14.         }
  15.     }
  16. }
複製代碼

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}},{{13,14,15,16},{17,18,19,20},{21,22,23,24}}};
  6.         for(int i=0; i<2; i++)
  7.         {
  8.             for(int j=0; j<3; j++)
  9.             {
  10.                 for(int k=0; k<4; k++)
  11.                 {
  12.                     System.out.println("n["+i+"]["+j+"]["+k+"]"+n[i][j][k]);
  13.                 }
  14.             }
  15.         }
  16.     }
  17. }
複製代碼

TOP

  1. //2x3x4
  2. public class Ch37
  3. {
  4.     public static void main(String args[])
  5.     {
  6.         int n[][][]={{{1,2,3,4},{5,6,7,8},{9,10,11,12}},
  7.                      {{13,14,15,16},{17,18,19,20},{21,22,23,24}}};
  8.         for(int i=0; i<2; i++)
  9.         {
  10.             for(int j=0; j<3; j++)
  11.             {
  12.                 for(int k=0; k<4; k++)
  13.                     System.out.println("n["+i+"]["+j+"]["+k+"]="+n[i][j][k]);
  14.             }
  15.         }
  16.     }
  17. }
複製代碼

TOP

  1. public class Ch01
  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.                      {{13,14,15,16},{17,18,19,20},{21,22,23,24}}};
  7.         for(int i=0; i<2; i++)
  8.         {
  9.             for(int j=0; j<3; j++)
  10.             {
  11.                 for(int k=0; k<4; k++)
  12.                     System.out.println("n["+i+"]["+j+"]["+k+"]="+n[i][j][k]);
  13.             }
  14.         }
  15.     }
  16. }
複製代碼

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.                      {{13,14,15,16},{17,18,19,20},{21,22,23,24}}};
  7.         for(int i=0; i<2; i++)
  8.         {
  9.             for(int j=0; j<3; j++)
  10.             {
  11.                 for(int k=0; k<4; k++)
  12.                     System.out.println("n["+i+"]["+j+"]["+k+"]="+n[i][j][k]);
  13.             }
  14.         }
  15.     }
  16. }
複製代碼

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.                      {{13,14,15,16},{17,18,19,20},{21,22,23,24}}};
  7.         for(int i=0; i<2; i++)
  8.         {
  9.             for(int j=0; j<3; j++)
  10.             {
  11.                 for(int k=0; k<4; k++)
  12.                     System.out.println("n["+i+"]["+j+"]["+k+"]="+n[i][j][k]);
  13.             }
  14.         }
  15.     }
  16. }
複製代碼

TOP

返回列表