Presentation is loading. Please wait.

Presentation is loading. Please wait.

Multidimensional Array 2010.11.26. Outline Two-Dimensional Arrays Lengths of Two-Dimensional Arrays Multidimension Arrays [Sample code]

Similar presentations


Presentation on theme: "Multidimensional Array 2010.11.26. Outline Two-Dimensional Arrays Lengths of Two-Dimensional Arrays Multidimension Arrays [Sample code]"— Presentation transcript:

1 Java @Ch6. Multidimensional Array 2010.11.26

2 Outline Two-Dimensional Arrays Lengths of Two-Dimensional Arrays Multidimension Arrays [Sample code]

3 Two-Dimensional Arrays 陣列變數型態 [] [] 陣列名稱 ; Ex: int [][] Array; int [][] Array = new int[5] [5]; int [][] Array = { {1,2,3}, {4,5,6} };

4 4 123 456 789 [0] [1] [2] [0] [1] [2] [0] [1] [2] Matrix = new int[3][3];Matrix[1][0] = 4;int [ ][ ] Matrix= { {1,2,3}, {4,5,6}, {7,8,9} }; 宣告 3x3 空陣列 Assign 整數 4 給陣列 [1][0] 宣告 3x3 陣列並且 assign 初始值

5 Lengths of Two-Dimensional Arrays 二維陣列的每個元素都是一個一維陣列 ( 課本 p.261) EX: int A= new int [3][4]; A[0][0]A[0][1]A[0][2]A[0][3] A[1][0]A[1][1]A[1][2]A[1][3] A[2][0]A[2][1]A[2][2]A[2][3] A A[0] A[1] A[2] A.length = 3 A[0].length = 4 A[1].length = 4 A[2].length = 4

6 練習一 : 將整數 65~122 強制轉成字元印出來 ※印出 (char)number

7 練習二 : 1. 宣告一個二維 3x4 陣列 Matrix 2. 利用兩個 for 迴圈來 assign 陣列的元 素值, 並且內容為 a~z 的亂數

8 Multidimension Arrays EX: int [][][] A = new int [3][4][2]; A[0][0]A[0][1]A[0][2]A[0][3] A A[0] A[1] A[2] A[0].length = 4 A[0][0][0]A[0][0][1]A[0][1][0]A[0][1][1] A[0][0].length = 2A[0][1].length = 2 A.length = 3


Download ppt "Multidimensional Array 2010.11.26. Outline Two-Dimensional Arrays Lengths of Two-Dimensional Arrays Multidimension Arrays [Sample code]"

Similar presentations


Ads by Google