for (int k = 0; k < a[0].length; k++) { int last = a.length - 1; a[0][k] = a[last][k]; a[last][k] = a [0][k]; } Consider the following method intended to swap the first and last rows in a two-dimensional array: public static void swapRow (int[][] a) { /* missing code */ } Which of the following correctly replaces /* missing code */? | None of the answers listed. | | for (int k = 0; k < a[0].length; k++) { int last = a.length; int temp = a [0][k]; a[0][k] = a[last][k]; a[last][k] = temp; } | | for (int k = 0; k < a[0].length; k++) { int last = a.length - 1; int temp = a [0][k]; a[0][k] = a[last][k]; a[last][k] = temp; } | | for (int k = 0; k < a[0].length; k++) { int last = a.length; a[0][k] = a[last][k]; a[last][k] = a [0][k]; } | | for (int k = 0; k < a[0].length; k++) { int last = a.length - 1; a[0][k] = a[last][k]; a[last][k] = a [0][k]; } | Consider the following method declaration. public static void increment(int[][] a) { for (int r = 0; r < a.length; r++) { for (int c = 0; c < a[0].length; c++) { if (a[r][c] >= 0) { a[r][c]++; } else { a[r][c]--; } } } } Assume the 2D array, matrix, has been initialized to the following values: 4 6 -15 5 11 21 -11 -10 3 4 -10 -18 -21 14 -23 What is the value of matrix after the method call, increment(matrix);? | 5 7 -14 6 12 22 -10 -9 4 5 -9 -17 -20 15 -22 | | 5 7 -15 6 12 22 -11 -10 4 5 -10 -18 -21 15 -23 | | 5 7 -16 6 12 22 -12 -11 4 5 -11 -19 -22 15 -24 | | 4 6 -16 5 11 21 -12 -11 3 4 -11 -19 -22 14 -24 | | 4 6 -15 5 11 21 -11 -10 3 4 -10 -18 -21 14 -23 | Consider the following code. int[][] matrix = new int[4][5]; Suppose we want to initialize matrix to the following rows and columns. 0 1 2 3 4 4 3 2 1 0 0 1 2 3 4 4 3 2 1 0 Which of the options below correctly initializes matrix? I. for (int i = 0; i < matrix.length; i += 2) { for (int j = 0; j < matrix[i].length; j++) { matrix[i][j] = j; matrix[i + 1][j] = j; } } II. for (int i = 0; i < matrix.length; i += 2) { for (int j = 0; j < matrix[i].length; j++) { matrix[i][j] = j; matrix[i + 1][matrix[i].length - j - 1] = j; } } III. for (int i = 0; i < matrix.length; i += 2) { for (int j = 0; j < matrix[i].length; j++) { matrix[i][j] = j; matrix[i + 1][matrix[i].length - j - 1] = i; } } | III only Consider the following code: int[][] grid = /* code not shown */; Which of the following could be used to calculate how many cells are in the array? | grid.length[0] * grid[0].length | | grid.length * grid[0].length | | grid.length * grid.length | | grid.length Consider the following declaration for a two-dimensional array. int[][] grid = new int[3][5]; int c = 0; for (int i = 0; i < grid.length; i++) { for (int j = 0; j < grid[i].length; j++) { grid[i][j] = c; c++; } } What element is displayed when the following line of code is executed? System.out.println(grid[2][1]); | 12 What does the following segment of code do? int[][] a = /* initialization not shown */; int sum = 0; for(int i = 0; i < a.length; i++) { for(int j = 0; j < a[0].length; j++) { if(i % 2 == 0) { sum += a[i][j]; } } } | It finds the sum of every other element in the array. | | It finds the sum of the elements in the even rows in the array. | | It finds the sum of the elements in the even columns in the array. | | It finds the sum of all elements in the array. | | It finds the sum of the even elements in the array. Which option best describes what the following algorithm does? int a [][] = /* initialization not shown */; int j = 2; for (int i = 0; i < a[0].length; i++) { int temp = a[j + 1][i]; a[j + 1][i] = a[j][i]; a[j][i] = temp; } | Initializes the values in the array. | | Swaps rows 2 and 3. You need a method to find the maximum value in every row of an array. Which of the following methods works as intended? I. public static int[] findMaxList (int a[][]) { int temp [] = new int [a.length]; for(int i = 0; i < a.length; i++) { int max = a[i][0]; for(int j = 0; j < a[0].length; j++) { if (a[i][j] > max) { max = a[0][j]; } } temp [i] = max; } return temp; } II. public static int[] findMaxList (int a[][]) { int temp [] = new int [a.length]; for(int i = 0; i < a.length; i++) { int max = a[i][0]; for(int j =0; j < a[0].length; j++) { if (a[i][j] > max) { max = a[i][j]; } } temp [i] = max; } return temp; } III. public static int[] findMaxList (int a[][]) { int temp [] = new int [a.length]; for(int i = 0; i < a.length; i++) { int max = a[i][0]; for(int j = 0; j < a[0].length; j++) { if(a[i][j] > a[0][j]) { max = a[i][j]; } } temp [i] = max; } return temp; } | | | | | |