目录
1. (单选题)How many elements are in array matrix (int[][] matrix = new int[5][5])?
3. (单选题)Analyze the following code.int[] list = new int[5]; list = new int[6];
10. (单选题)Which correctly creates an array of five empty Strings?
11. (单选题)What is the index variable for the element at the first row and first column in array a?
20. (单选题)Assume double[][] x = new double[4][5], what are x.length and x[2].length?
21. (单选题)When you return an array from a method, the method returns .
24. (单选题)The method copies the sourceArray to the targetArray.
25. (单选题)When you pass an array to a method, the method receives .
27. (单选题)Which of the following statements are correct?
28. (单选题)Assume int[][] x = { {1, 2}, {3, 4}, {5, 6}}, what are x.length are x[0].length?
30. (多选题)Which of the following declarations are correct?
一. 单选题
1. (单选题)How many elements are in array matrix (int[][] matrix = new int[5][5])?
- A. 14
- B. 20
- C. 25
- D. 30
我的答案: C
2. (单选题)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
3. (单选题)Analyze the following code.
int[] list = new int[5]; list = new int[6];
- A. The code has compile errors because the variable list cannot be changed once it is assigned.
- B. The code has runtime errors because the variable list cannot be changed once it is assigned.
- C. The code can compile and run fine. The second line assigns a new array to list.
- D. The code has compile errors because you cannot assign a different size array to list.
我的答案: C
4. (单选题)Analyze the following code:
public class Test {
public static void main(String[] args) { int[] x = new int[5];
int i;
for (i = 0; i < x.length; i++) x[i] = i; System.out.println(x[i]);
}
}
- A. The program displays 0 1 2 3 4.
- B. The program displays 4.
- C. The program has a runtime error because the last statement in the main method causes ArrayIndexOutOfBoundsException.
- D. The program has a compile error because i is not defined in the last statement in the main method.
我的答案: C
5. (单选题)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
6. (单选题)Assume int[] scores = {1, 20, 30, 40, 50}, what is the output of System.out.println(java.util.Arrays.toString(scores))?
- A. {1, 20, 30, 40, 50}
- B. [1, 20, 30, 40, 50]
- C. {1 20 30 40 50}
- D. [1 20 30 40 50]
我的答案: B
7. (单选题)How can you get the word "abc" in the main method from the following call?
java Test "+" 3 "abc" 2
- A. args[0]
- B. args[1]
- C. args[2]
- D. args[3]
我的答案: C
8. (单选题)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
- B. 3
- C. 5
- D. 6
- E. 33
我的答案: A
9. (单选题)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
10. (单选题)Which correctly creates an array of five empty Strings?
- A. String[] a = new String [5];
- B. String[] a = {"", "", "", "", ""};
- C. String[5] a;
- D. String[ ] a = new String [5]; for (int i = 0; i < 5; a[i++] = null);
我的答案: B
11. (单选题)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
12. (单选题)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
13. (单选题)What would be the result of attempting to compile and run the following code?
public class Test {
public static void main(String[] args) { double[] x = new double[]{1, 2, 3}; System.out.println("Value is " + x[1]);
}
}
- A. The program has a compile error because the syntax new double[]{1, 2, 3} is wrong and it should be replaced by
{1, 2, 3}. - B. The program has a compile error because the syntax new double[]{1, 2, 3} is wrong and it should be replaced by new double[3]{1, 2, 3};
- C. The program has a compile error because the syntax new double[]{1, 2, 3} is wrong and it should be replaced by new double[]{1.0, 2.0, 3.0};
- D. The program compiles and runs fine and the output "Value is 1.0" is printed.
- E. The program compiles and runs fine and the output "Value is 2.0" is printed.
我的答案: E