Basics
Traversal
Simple Statements
100

Vocab: Vertical series of data in a 2D array

Column

100

True or False: You can not traverse a 2d array in column-major strictly using enhanced for loops

True

100

Initialize a new Int array with 5 rows and 4 columns

int[][] array = new int[4][5];

200

Vocab: An array nested within another Array

Inner Array

200

In order to traverse an arrays' column, what should your boolean be in your for loop?

column < array[0].length;

200

return the element in the 4th row and 3rd column

return array[3][2];

300

int[][] grid = {

{2, 3, 4, 4},

{4, 3, 4, 3},

{3, 2, 4, 3},

}

How many rows and columns are there in this array

3 rows and 4 columns

300

Write the outer and inner for loop to traverse a 2D String array, using enhanced for loops in row-major order

for (String[] row : array) {

for (String element : row) {


}

}

300

return the bottom right corner element

return array[array.length - 1][array[0].length - 1]

400

In context of rows and columns, array.length returns the total number of what in the array?

rows

400

int[][] array = {
{2, 3},
{4, 5}
};

for (int i = 0; i < array.length; i++) {
for (int j = 0; j < array[i].length; j++) {
array[i][j] = array[i][j] + i + j;
}
}

What will be printed when array is printed

{ {2, 4}, 

{5, 7} }

400

return the element in the 2nd row and 2nd to last column

return array[2][array[0].length - 2];

500

If you attempt to access an element which does not exist, what error does Java throw at you

ArrayIndexOutOfBoundsException

500

Print every element in a 2D double array using a regular for loop for the outer loop and an enhanced for loop for the inner loop.

Column-Major

for (int col = 0; col < array[0].length; col ++) {

for (double[] element : array) {

System.out.println(element[col]);

}

}

500

return the very center element assuming, there are an odd number of rows and columns.

return array[array.length / 2][array[0].length / 2];

M
e
n
u