Beruflich Dokumente
Kultur Dokumente
OBJECTIVES :
multidimensional array :
Define an array Declare and initialize an array Pass array to methods Return array to methods Write program using single array
2D Array
arrays with more than one dimension.
Syntax
Give the value of the following elements in the 2-D representation seen in Slide 10:
marks_table[0][0] marks_table[1][1]
marks_table[3][0]
marks_table[4][2]
For example, if you need to print the value stored in first row and second column of the array marks_table, (i.e. chemistry mark of student 2) the code will be :
Example
System.out.println(marks_table[1][2]);
{ System.out.println("Marks : "+marks[x][y]); } }
Examine the following: double values[][] = { {1.2, 9.0, 3.2}, {9.2, 0.5, 1.5, -1.2}, {7.3, 7.9, 4.8} } ;
What is the value of values[2][1]? a. 7.3 b. 7.9 c. 9.2 d. There is no such array element
12 7 -32
-9 14 -1
Choose the correct declaration from the declaration statements given: Declaration A Declaration B Declaration C Declaration D
double table [ ][ ] double table[ ][ ] double table[ ][ double table[ ][ = { 12, -9, 8, = { {12, -9, 8}, ] = { {12, -9, 8} ] = { {12, -9, 8}, 7, 14, {7, 14, 0}, {7, 14} {7, 14}, -32, -1, 0} ; -32, -1, 0} }; {-32, -1, 0} }; {-32, -1, 0} };
Which of the following statements constructs an array with 5 rows of 7 columns? long stuff[][] = new stuff[5][7]; long stuff[][] = new long[5][7]; long stuff[][] = long[5][7]; long stuff[][] = long[7][5];
Which of the following statements that constructs a two-dimensional array with 7 rows? int array[ ][ ] = new int[7][ ]; int array[ ][ ] = new int[][]; int array[ ][ ] = new int[ ][7]; int[] array[7] = new int[ ];
OOP in Java