Quiz
ch_7
Fragen in diesem Quiz (19)
1Which of the following statements are correct?
- Achar[][] charArray = {'a', 'b'};
- Bchar[2][2] charArray = {{'a', 'b'}, {'c', 'd'}};
- Cchar[2][] charArray = {{'a', 'b'}, {'c', 'd'}};
- Dchar[][] charArray = {{'a', 'b'}, {'c', 'd'}};
2Assume double[][] x = new double[4][5], what are x.length and x[2].length?
- A4 and 4
- B4 and 5
- C5 and 4
- D5 and 5
3What is the index variable for the element at the first row and first column in array a?
- Aa[0][0]
- Ba[1][1]
- Ca[0][1]
- Da[1][0]
4When you create an array using the following statement, the element values are automatically initialized to 0.
int[][] matrix = new int[5][5];- ATrue
- BFalse
5How many elements are array matrix (int[][] matrix = new int[5][5])?
- A14
- B20
- C25
- D30
6Analyze 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]);
}
}- AThe program has a compile error because new boolean[3][] is wrong.
- BThe program has a runtime error because x[2][2] is null.
- CThe program runs and displays x[2][2] is null.
- DThe program runs and displays x[2][2] is true.
- EThe program runs and displays x[2][2] is false.
7Assume int[][] x = {{1, 2}, {3, 4}, {5, 6}}, what are x.length are x[0].length?
- A2 and 1
- B2 and 2
- C3 and 2
- D2 and 3
- E3 and 3
8Assume int[][] x = {{1, 2}, {3, 4, 5}, {5, 6, 5, 9}}, what are x[0].length, x[1].length, and x[2].length?
- A2, 3, and 3
- B2, 3, and 4
- C3, 3, and 3
- D3, 3, and 4
- E2, 2, and 2
9 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);
}
}- A1
- B3
- C5
- D6
- E33
10What 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);
}
}- A1
- B3
- C5
- D6
- E33
11What 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();
}
}
}- AThe program prints two rows 3 4 5 1 followed by 33 6 1 2
- BThe program prints on row 3 4 5 1 33 6 1 2
- CThe program prints two rows 1 3 4 5 followed by 1 2 6 33
- DThe program prints one row 1 3 4 5 1 2 6 33
12What 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] + " ");
}
}- A1 2 3 4
- B4 5 6 7
- C1 3 8 12
- D2 5 9 13
- E3 6 10 14
13What 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] + " ");
}
}- A1 2 3 4
- B4 5 6 7
- C1 3 8 12
- D2 5 9 13
- E3 6 10 14
14Suppose a method p has the following heading:
public static int[][] p()
What return statement may be used in p()?- Areturn 1;
- Breturn {1, 2, 3};
- Creturn int[]{1, 2, 3};
- Dreturn new int[]{1, 2, 3};
- Ereturn new int[][]{{1, 2, 3}, {2, 4, 5}};
15What 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;
}
}- A3 33
- B1 1
- C5 6
- D5 33
- E33 5
16Assume double[][][] x = new double[4][5][6], what are x.length, x[2].length, and x[0][0].length?
- A4, 5, and 6
- B6, 5, and 4
- C5, 5, and 5
- D4, 5, and 4
17Which of the following statements are correct?
- Achar[][][] charArray = new char[2][2][];
- Bchar[2][2][] charArray = {'a', 'b'};
- Cchar[][][] charArray = {{'a', 'b'}, {'c', 'd'}, {'e', 'f'}};
- Dchar[][][] charArray = {{{'a', 'b'}, {'c', 'd'}, {'e', 'f'}}};
18What 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]);
}
}- A1
- B2
- C3
- D4
- E5
- F6
19What 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;
}
}- A1
- B2
- C4
- D5
- E6
Informationen
- Beschreibung
- Chapter 7
- Autor
- Joshua Villy
- Sprache
- English
- Aufrufe
- 834
- Schlagwörter
- Bewertung
- Noch keine Bewertungen Bewerte dieses Quiz