Board logo

標題: 陣列 (四) [打印本頁]

作者: tonyh    時間: 2012-11-3 16:19     標題: 陣列 (四)

本帖最後由 tonyh 於 2012-11-3 16:26 編輯

三維陣列的練習,
試宣告一個3x3x3的三維陣列,
總共可儲存27筆資料.
  1. public class ch38
  2. {
  3.     public static void main(String args[])
  4.     {
  5.         int a[][][]={{{1,2,3},{4,5,6},{7,8,9}},
  6.                      {{10,11,12},{13,14,15},{16,17,18}},
  7.                      {{19,20,21},{22,23,24},{25,26,27}}};
  8.         for(int i=0; i<=2; i++)
  9.         {
  10.             for(int j=0; j<=2; j++)
  11.             {
  12.                for(int k=0; k<=2; k++)
  13.                {
  14.                   System.out.println("a["+i+"]["+j+"]["+k+"]="+a[i][j][k]);
  15.                }
  16.             }
  17.         }
  18.     }
  19. }
複製代碼

作者: 黃博鴻    時間: 2012-11-3 16:26

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

作者: t2364705    時間: 2012-11-3 16:27

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

作者: t3742238    時間: 2012-11-3 16:29

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

作者: 劉漢文    時間: 2012-11-3 16:29

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

作者: 尤泓鈞    時間: 2012-11-3 16:31

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

作者: 粘靖瑜    時間: 2012-11-3 16:31

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

作者: 蔡昀佑    時間: 2012-11-3 16:31

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





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