2D Arrays
A 2D double array is declared and initialized to track the terrain of a city park. Each value in the 2D array represents the height of a particular latitude and longitude above sea level. Longitude is represented by the columns in the 2D array and latitude is represented by each row in the 2D array.The creator of this 2D array would like to look at the height of the city park along the longitude 100.0 - what traversal method would make the most sense in order to do so?
Column-Major Order
How do you find the arr[n].length?
It is the number of elements in the nth row.
What is the length of a 2d array?
It is the number of rows.
How do you find the value of arr[x][y]?
Start with array that is x - 1 and count over to element y - 1.
How can you create a 2D double array with 6 rows and 7 columns and assign it to connectFour?
double[ ][ ] connectFour = new double[6][7]
Given the array int [ ] [ ] array = { {1, 2, 3}, {4, 5, 6}, {7, 8, 9} } What is array[0][1] + array[2][0]?
9
Given int[ ][ ] grid = new int[5][3], what is the value of grid[0].length?
3
What is the proper syntax to initialize an empty 6x6 2D String array?
String[ ][ ] array = new String[6][6];
Which is the correct way to construct and assign a 2D array, with 8 rows, to popcorn, but does not have the rows constructed yet?
int[ ][ ] popcorn = new int[8][ ];