ch_7

Question 1 of 19

Medal-premium 1

Which of the following statements are correct?

Select one of the following:

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

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

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

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

Question 2 of 19

Medal-premium 1

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

Select one of the following:

  • 4 and 4

  • 4 and 5

  • 5 and 4

  • 5 and 5

Question 3 of 19

Medal-premium 1

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

Select one of the following:

  • a[0][0]

  • a[1][1]

  • a[0][1]

  • a[1][0]

Question 4 of 19

Medal-premium 1

When you create an array using the following statement, the element values are automatically initialized to 0.

int[][] matrix = new int[5][5];

Select one of the following:

  • True

  • False

Question 5 of 19

Medal-premium 1

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

Select one of the following:

  • 14

  • 20

  • 25

  • 30

Question 6 of 19

Medal-premium 1

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

Select one of the following:

  • The program has a compile error because new boolean[3][] is wrong.

  • The program has a runtime error because x[2][2] is null.

  • The program runs and displays x[2][2] is null.

  • The program runs and displays x[2][2] is true.

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

Question 7 of 19

Medal-premium 1

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

Select one of the following:

  • 2 and 1

  • 2 and 2

  • 3 and 2

  • 2 and 3

  • 3 and 3

Question 8 of 19

Medal-premium 1

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

Select one of the following:

  • 2, 3, and 3

  • 2, 3, and 4

  • 3, 3, and 3

  • 3, 3, and 4

  • 2, 2, and 2

Question 9 of 19

Medal-premium 1

What will be displayed by 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);
}
}

Select one of the following:

  • 1

  • 3

  • 5

  • 6

  • 33

Question 10 of 19

Medal-premium 1

What will be displayed by 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);
}
}

Select one of the following:

  • 1

  • 3

  • 5

  • 6

  • 33

Question 11 of 19

Medal-premium 1

What will be displayed by 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();
}
}
}

Select one of the following:

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

  • The program prints on row 3 4 5 1 33 6 1 2

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

  • The program prints one row 1 3 4 5 1 2 6 33

Question 12 of 19

Medal-premium 1

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

Select one of the following:

  • 1 2 3 4

  • 4 5 6 7

  • 1 3 8 12

  • 2 5 9 13

  • 3 6 10 14

Question 13 of 19

Medal-premium 1

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

Select one of the following:

  • 1 2 3 4

  • 4 5 6 7

  • 1 3 8 12

  • 2 5 9 13

  • 3 6 10 14

Question 14 of 19

Medal-premium 1

Suppose a method p has the following heading:

public static int[][] p()

What return statement may be used in p()?

Select one of the following:

  • return 1;

  • return {1, 2, 3};

  • return int[]{1, 2, 3};

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

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

Question 15 of 19

Medal-premium 1

What will be displayed by 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;
}
}

Select one of the following:

  • 3 33

  • 1 1

  • 5 6

  • 5 33

  • 33 5

Question 16 of 19

Medal-premium 1

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

Select one of the following:

  • 4, 5, and 6

  • 6, 5, and 4

  • 5, 5, and 5

  • 4, 5, and 4

Question 17 of 19

Medal-premium 1

Which of the following statements are correct?

Select one or more of the following:

  • char[][][] charArray = new char[2][2][];

  • char[2][2][] charArray = {'a', 'b'};

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

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

Question 18 of 19

Medal-premium 1

What will be displayed by 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]);
}
}

Select one of the following:

  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

Question 19 of 19

Medal-premium 1

What will be displayed by 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;
}
}

Select one of the following:

  • 1

  • 2

  • 4

  • 5

  • 6

Icon_fullscreen
Joshua Villy
Quiz by , created about 1 year ago

Chapter 7

Eye 320
Pin 0
Balloon-left 0
Tags
Joshua Villy
Created by Joshua Villy about 1 year ago
Close