D8 - M
Assume double[][] x = new double[4][5], what are x.length and x[2].length? a. 4 and 4 b. 4 and 5 c. 5 and 4 d. 5 and 5
b
Assume double[][][] x = new double[4][5][6], what are x.length, x[2].length, and x[0][0].length? a. 4, 5, and 6 b. 6, 5, and 4 c. 5, 5, and 5 d. 4, 5, and 4
a
Assume boolean[][] x = new boolean[5][7], what are x.length and x[2].length? a. 4 and 4 b. 4 and 5 c. 5 and 7 d. 5 and 5 E. 5 and 6
c
Given the following declaration: int[][] m = new int[5][6]; Which of the following statements is true? a. The name m represents a two-dimensional array of 30 int values. b. m[2][4] represents the element stored in the 2nd row and the 4th column of m. c. m.length has the value 6. d. m[0].length has the value 5.
a
What is the index variable for the element at the first row and first column in array a? a. a[0][0] b. a[1][1] c. a[0][1] d. a[1][0]
a
Assume int[][][] x = new char[2][5][3], how many elements are in the array? a. 30 b. 35 c. 40 d. 45
a
When you create an array using the following statement, the element values are automatically initialized to 0. int[][] matrix = new int[5][5]; a. True b. False
a
Analyze the following code: int[][] matrix = new int[5][5]; for (int column = 0; column < matrix[4].length; column++) matrix[4][column] = 10; a. After the loop, the last column of matrix 10, 10, 10, 10, 10. b. After the loop, the last row of matrix 10, 10, 10, 10, 10. c. After the loop, the last row of matrix 0, 0, 0, 0, 0. d. After the loop, the last row of matrix 0, 0, 0, 0, 10.
b
Assume boolean[][] x = new boolean[5][7], what is the index variable for the element at the last row and last column in array x? a. x[4][5] b. x[4][6] c. x[5][6] d. x[5][7]
b
Consider the following statements: int[][] numbers = {{1}, {1, 2}, {1, 2, 3}}; What is numbers.length and what is numbers[1].length? a. 3, 1 b. 3, 2 c. 3, 3 d. 2, 2 d. 1, 3
b
Analyze the following code: public class Test { public static void main(String[] args) { boolean[][] x = new boolean[3][]; x[0] = new boolean[1]; x[1] = new boolean[2]; x[2] = new boolean[3]; System.out.println("x[2][2] is " + x[2][2]); } } a. The program has a compile error because new boolean[3][] is wrong. b. The program has a runtime error because x[2][2] is null. c. The program runs and displays x[2][2] is null. d. The program runs and displays x[2][2] is true. e. The program runs and displays x[2][2] is false. Assume int[][] x = {{1, 2}, {3, 4}, {5, 6}}, what are x.length are x[0].length? a. 2 and 1 b. 2 and 2 c. 3 and 2 d. 2 and 3 e. 3 and 3
c
What is the output of the following code? public class Test { public static void main(String[] args) { int[][] matrix = {{1, 2, 3, 4}, {4, 5, 6, 7}, {8, 9, 10, 11}, {12, 13, 14, 15}}; for (int i = 0; i < 4; i++) System.out.print(matrix[i][1] + " "); } } a. 1 2 3 4 b. 4 5 6 7 c. 1 3 8 12 d. 2 5 9 13 e. 3 6 10 14
d
What is the printout of the following code? public class Test { public static void main(String[] args) { int[][][] data = {{{1, 2}, {3, 4}}, {{5, 6}, {7, 8}}}; System.out.print(data[1][0][0]); } } a. 1 b. 2 c. 4 d. 5 e. 6
d
What is the output of the following code? public class Test { public static void main(String[] args) { int[][] matrix = {{1, 2, 3, 4, 5}, {4, 5, 6, 4, 7}, {8, 9, 10, 11}, {12, 13, 14, 15}}; for (int i = 0; i < matrix.length; i++) System.out.print(matrix[i][3] + " "); } } a. 1 2 3 4 b. 4 5 6 7 c. 1 3 8 12 d. 2 5 9 13 E. 4 4 11 15
e
What is the printout of the following program? public class Test { public static void main(String[] args) { int[][] values = {{3, 4, 5, 1}, {33, 6, 1, 2}}; int v = values[0][0]; for (int row = 0; row < values.length; row++) for (int column = 0; column < values[row].length; column++) if (v < values[row][column]) v = values[row][column]; System.out.print(v); } } a. 1 b. 3 c. 5 d. 6 e. 33
e
What is the printout of the following program? public class Test { public static void main(String[] args) { int[][] values = {{3, 4, 5, 1}, {33, 6, 1, 2}}; int v = values[0][0]; for (int[] list : values) for (int element : list) if (v > element) v = element; System.out.print(v); } } a. 1 b. 3 c. 5 d. 6 e. 33
a
What statement can be used to invoke the following method? public static int m(int[][] m) { // Implementation omitted } a. new int[][]{{1, 2}, {3, 4}} b. new int[]{{1, 2}, {3, 4}} c. new double[][]{{1, 2}, {3, 4}} d. new double[]{{1, 2}, {3, 4}}
a
Which of the following statements are correct? a. char[][][] charArray = new char[2][2][]; b. char[2][2][] charArray = {'a', 'b'}; c. char[][][] charArray = {{'a', 'b'}, {'c', 'd'}, {'e', 'f'}}; d. char[][][] charArray = {{{'a', 'b'}, {'c', 'd'}, {'e', 'f'}}};
a
Assume int[][] x = {{1, 2}, {3, 4, 5}, {5, 6, 5, 9}}, what are x[0].length, x[1].length, and x[2].length? a. 2, 3, and 3 b. 2, 3, and 4 c. 3, 3, and 3 d. 3, 3, and 4 e. 2, 2, and 2
b
What is the output of the following code? public class Test5 { public static void main(String[] args) { int[][] matrix = {{1, 2, 3, 4}, {4, 5, 6, 7}, {8, 9, 10, 11}, {12, 13, 14, 15}}; for (int i = 0; i < 4; i++) System.out.print(matrix[1][i] + " "); } } a. 1 2 3 4 b. 4 5 6 7 c. 1 3 8 12 d. 2 5 9 13 e. 3 6 10 14
b
Which of the following is correct to create an array? a. int[][] m = {1, 2}; b. int[][] m = {{1, 2}}; c. int[][] m = {{1, 2}, {3, 4}}; d. int[][] m = {{1, 2}; {3, 4}}; E. int[][] m = {{1, 2}, {3, 4}, };
b
Assume int[][] x = {{1, 2, 3}, {3, 4, 5, 5}, {5, 6}}, what are x.length are x[1].length? a. 2 b. 3 c. 4 d. 5
c
How many elements are array matrix (int[][] matrix = new int[5][5])? a. 14 b. 20 c. 25 d. 30
c
Show the printout of the following code. public class Test { public static void main(String[] args) { double[][] m = {{1, 2, 3}, {1.5, 2.5, 3.5}, {0.1, 0.1, 0.1}}; System.out.println(sum(m)); } public static double sum(double[][] m) { double sum = 0; for (int i = 0; i < m.length; i++) sum += m[i][i]; return sum; } } a. 3 b. 3.0 c. 3.6 d. 4 e. 4.0
c
What is the printout of the following code? public class Test { public static void main(String[] args) { int[][][] data = {{{1, 2}, {3, 4}}, {{5, 6}, {7, 8}}}; System.out.print(ttt(data[0])); } public static int ttt(int[][] m) { int v = m[0][0]; for (int i = 0; i < m.length; i++) for (int j = 0; j < m[i].length; j++) if (v < m[i][j]) v = m[i][j]; return v; } } a. 1 b. 2 c. 4 d. 5 e. 6
c
Assume char[][][] x = new char[14][5][16], what are x.length, x[2].length, and x[0][0].length? a. 13, 5, and 16 b. 13, 5, and 15 c. 12, 5, and 15 d. 14, 5, and 16
d
What is the printout of the following program? public class Test { public static void main(String[] args) { int[][] values = {{3, 4, 5, 1 }, {33, 6, 1, 2}}; for (int row = 0; row < values.length; row++) { java.util.Arrays.sort(values[row]); for (int column = 0; column < values[row].length; column++) System.out.print(values[row][column] + " "); System.out.println(); } } } a. The program prints two rows 3 4 5 1 followed by 33 6 1 2 b. The program prints on row 3 4 5 1 33 6 1 2 c. The program prints two rows 3 4 5 1 followed by 33 6 1 2 d. The program prints two rows 1 3 4 5 followed by 1 2 6 33 e. The program prints one row 1 3 4 5 1 2 6 33
d
What is the printout of the following program? public class Test { public static void main(String[] args) { int[][] values = {{3, 4, 5, 1}, {33, 6, 1, 2}}; for (int row = 0; row < values.length; row++) { System.out.print(m(values[row]) + " "); } } public static int m(int[] list) { int v = list[0]; for (int i = 1; i < list.length; i++) if (v < list[i]) v = list[i]; return v; } } a. 3 33 b. 1 1 c. 5 6 d. 5 33 e. 33 5
d
Which of the following statements are correct? a. char[][] charArray = {'a', 'b'}; b. char[2][2] charArray = {{'a', 'b'}, {'c', 'd'}}; c. char[2][] charArray = {{'a', 'b'}, {'c', 'd'}}; d. char[][] charArray = {{'a', 'b'}, {'c', 'd'}};
d
Analyze the following code: int[][] matrix = new int[5][5]; for (int column = 0; column < matrix[4].length; column++); matrix[4][column] = 10; a. After the loop, the last column of matrix 10, 10, 10, 10, 10. b. After the loop, the last row of matrix 10, 10, 10, 10, 10. c. After the loop, the last row of matrix 0, 0, 0, 0, 0. d. After the loop, the last row of matrix 0, 0, 0, 0, 10. e. A syntax error, because column is not defined.
e
Suppose a method p has the following heading: public static int[][] p() What return statement may be used in p()? a. return 1; b. return {1, 2, 3}; c. return int[]{1, 2, 3}; d. return new int[]{1, 2, 3}; e. return new int[][]{{1, 2, 3}, {2, 4, 5}};
e