Chapter 8 CPS

¡Supera tus tareas y exámenes ahora con Quizwiz!

How many elements are array matrix (int[][] matrix = new int[5][5])?

C. 25

What is the output 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; } }

C. 4

Assume boolean[][] x = new boolean[5][7], what are x.length and x[2].length?

C. 5 and 7

What is the output 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]); } }

D. 5

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; } }

D. 5 33

What is the output 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(); } } }

D. The program prints two rows 1 3 4 5 followed by 1 2 6 33

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]); } }

E. The program runs and displays x[2][2] is false.

Suppose a method p has the following heading: public static int[][] p() What return statement may be used in p()?

E. return new int[][]{{1, 2, 3}, {2, 4, 5}};

Assume int[][] x = {{1, 2}, {3, 4, 5}, {5, 6, 5, 9}}, what are x[0].length, x[1].length, and x[2].length?

B. 2, 3, and 4

Assume int[][] x = {{1, 2}, {3, 4}, {5, 6}}, what are x.length are x[0].length?

C. 3 and 2

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; } }

3.6

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); } }

33

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] + " "); } }

4 4 11 15

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] + " "); } }

4 5 6 7

Assume double[][] x = new double[4][5], what are x.length and x[2].length?

4 and 5

Consider the following statements: int[][] numbers = {{1}, {1, 2}, {1, 2, 3}}; What is numbers.length and what is numbers[1].length?

B. 3, 2

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] + " "); } }

B. 4 5 6 7

ANALYZE THE FOLLOWING CODE: INT[][] MATRIX = NEW INT[5][5]; FOR (INT COLUMN = 0; COLUMN < MATRIX[4].LENGTH; COLUMN++) MATRIX[4][COLUMN] = 10;

B. After the loop, the last row of matrix 10, 10, 10, 10, 10.

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?

x[4][6]

GIVEN THE FOLLOWING DECLARATION: INT[][] M = NEW INT[5][6]; WHICH OF THE FOLLOWING STATEMENTS IS TRUE?

The name m represents a two-dimensional array of 30 int values.

Assume char[][][] x = new char[14][5][16], what are x.length, x[2].length, and x[0][0].length?

14, 5, and 16

What is the index variable for the element at the first row and first column in array a?

A. a[0][0]

What is the output 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

Assume int[][][] x = new char[2][5][3], how many elements are in the array?

A. 30

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

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

Which of the following statements are correct?

A. char[][][] charArray = new char[2][2][]; D. char[][][] charArray = {{{'a', 'b'}, {'c', 'd'}, {'e', 'f'}}};

2. 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]); } }

The program runs and displays x[2][2] is false.

Which of the following statements are correct?

char[][] charArray = {{'a', 'b'}, {'c', 'd'}};


Conjuntos de estudio relacionados

Interchange Book 2 Unit 4 Language summary

View Set

Chapter 12 and 13 Review Quiz (LAW)

View Set

Chapter 3: Databases and Data Warehouses

View Set