CPS180 Chapter 8 Quiz

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

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

1

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

14, 5, and 16

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

2 5 9 13

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

2, 3, and 4

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

25

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

3 and 2

int[][]numbers = {{1}, {1,2}, {1,2,3}}; What is numbers.length and what is numbers[1].length?

3,2

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

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

30

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

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

4

int[][]matrix = {{1,2,3,4}, {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

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

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

4, 5, and 6

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

4?

int[][][]data = {{{1,2}, {3,4}},{{5,6}, {7,8}}}; System.out.print(data[1][0][0]);

5

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

5 33

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

5 and 7

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

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

When you create an array using the following statement, the element values are automatically initialized to 0. int[][]matrix = new int[5][5];

true

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

x[2][2] is false

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]

int [][] matrix = new int[5][5]; for(int column = 0; column<matrix[4].length; column++) matrix[4][column] = 10;

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

int[][]m = new int[5][6]; Which is true?

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

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

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

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

a[0][0]

Which of the following statements are correct?

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

What statement can be used to invoke the following method? public static int m(int[][]m)

new int[][]{{1, 2}, {3, 4}}


Ensembles d'études connexes

Chapter 27: Lower Respiratory Problems

View Set

Gen Bio Chapter 11 - Human Organization Quiz

View Set

Study Guide: Unit 4 and 5 APUSH Exam

View Set

Chapter 6: Accounting for General Long- Term

View Set

Ética y Valores - 1.1 Breve Historia de la Ética (Resumen)

View Set

Exam 1 Intro To Weather and Climate

View Set

Economic Finals (Chapter 4 : Demand)

View Set