2.
The array size is specified when the array is declared.
判断题 (2 分) 2 分
- A.
false
- B.
true
8.
If a key is not in the list, the binarySearch method returns _________.
单选题 (1 分) 1 分
- A.
insertion point - 1
- B.
-(insertion point + 1)
- C.
insertion point
- D.
-insertion point
9.
Suppose int[] numbers = new int[10], what is numbers[0]?
单选题 (1 分) 1 分
- A.
10.
- B.
0
- C.
null
- D.
undefined.
14.
Which of the following declarations are correct?
多选题 (2 分) 2 分
- A.
public static void print(double... numbers)
- B.
public static double... print(double d1, double d2)
- C.
public static void print(int n, double... numbers)
- D.
public static void print(String... strings, double... numbers)
- E.
public static void print(double... numbers, String name)
15.
Identify the problems in the following code.
public class Test {
public static void main(String argv[]) {
System.out.println("argv.length is " + argv.length);
}
}
单选题 (1 分) 1 分
- A.
If you run this program without passing any arguments, the program would display argv.length is 0.
- B.
The program has a compile error because String args[] is wrong and it should be replaced by String args[].
- C.
The program has a compile error because String argv[] is wrong and it should be replaced by String[] args.
- D.
If you run this program without passing any arguments, the program would have a runtime error because argv is null.
18.
How can you initialize an array of two characters to 'a' and 'b'?
多选题 (2 分) 2 分
- A.
char[] charArray = {'a', 'b'};
- B.
char[2] charArray = {'a', 'b'};
- C.
char[] charArray = new char[2]; charArray = {'a', 'b'};
- D.
char[] charArray = new char[]{'a', 'b'};
19.
Analyze the following code:
public class Test {
public static void main(String[] args) {
double[] x = {2.5, 3, 4};
for (double value: x)
System.out.print(value + " ");
}
}
单选题 (1 分) 1 分
- A.
The program displays 2.5 3.0 4.0
- B.
The program has a syntax error because value is undefined.
- C.
The program displays 2.5, 3, 4
- D.
The program displays 2.5 3 4
- E.
The program displays 2.5, 3.0 4.0
20.
Which of the following is the correct header of the main method?
多选题 (2 分) 2 分
- A.
static void main(String[] args)
- B.
public static void main(String args[])
- C.
public static void main(String[] args)
- D.
public static void main(String x[])
- E.
public static void main(String[] x)
24.
Analyze the following code.
int[] list = new int[5];
list = new int[6];
单选题 (1 分) 1 分
- 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 has compile errors because you cannot assign a different size array to list.
- D.
The code can compile and run fine. The second line assigns a new array to list.
Analyze the following code:
public class Test {
public static void main(String[] args) {
int[] x = {1, 2, 3, 4};
int[] y = x;
x = new int[2];
for (int i = 0; i < y.length; i++)
System.out.print(y[i] + " ");
}
}
单选题 (1 分) 1 分
- A.
The program displays 0 0 3 4
- B.
The program displays 0 0
- C.
The program displays 0 0 0 0
- D.
The program displays 1 2 3 4
41.
The __________ method copies the sourceArray to the targetArray.
回答错误
单选题 (1 分) 0 分
- A.
System.copyArrays(sourceArray, 0, targetArray, 0, sourceArray.length);
- B.
System.arrayCopy(sourceArray, 0, targetArray, 0, sourceArray.length);
- C.
System.copyarrays(sourceArray, 0, targetArray, 0, sourceArray.length);
- D.
System.arraycopy(sourceArray, 0, targetArray, 0, sourceArray.length);
不懂为啥子不是驼峰命名
43.
Which of the following is correct?
多选题 (2 分) 2 分
- A.
String[] list = new String[]{"red", "yellow", "green"};
- B.
String[] list = {"red", "yellow", "green"};
- C.
String list = {"red", "yellow", "green"};
- D.
String list = new String{"red", "yellow", "green"};
- E.
String[] list = new String{"red", "yellow", "green"};
-
46.
The JVM stores the array in an area of memory, called _______, which is used for dynamic memory allocation where blocks of memory are allocated and freed in an arbitrary order.
单选题 (1 分) 1 分
- A.
stack
- B.
memory block
- C.
dynamic memory
- D.
heap
答案解释:
- A.
49.
Suppose a method p has the following heading:
public static int[] p()
What return statement may be used in p()?
单选题 (1 分) 1 分
- A.
return {1, 2, 3};
- B.
return 1;
- C.
return int[]{1, 2, 3};
- D.
return new int[]{1, 2, 3};
51.
The __________ method sorts the array scores of the double[] type.
单选题 (1 分) 1 分
- A.
Njava.util.Arrays.sortArray(scores)
- B.
java.util.Arrays(scores)
- C.
java.util.Arrays.sort(scores)
- D.
java.util.Arrays.sorts(scores)
53.
Assume int[] scores = {1, 20, 30, 40, 50}, what value does java.util.Arrays.binarySearch(scores, 3) return?
单选题 (1 分) 1 分
- A.
0
- B.
1
- C.
-2
- D.
2
- E.
-1
Assume double[] scores = {1, 2, 3, 4, 5}, what value does java.util.Arrays.binarySearch(scores, 3.5) return?
单选题 (1 分) 1 分
- A.
-3
- B.
-4
- C.
3
- D.
0
- E.
4
8.
If a key is not in the list, the binarySearch method returns _________.
单选题 (1 分) 1 分
- A.
insertion point - 1
- B.
-(insertion point + 1)
- C.
insertion point
- D.
-insertion point
58.
What is the correct term for numbers[99]?
单选题 (1 分) 1 分
- A.
index variable
- B.
indexed variable
- C.
index
- D.
array
- E.
array variable‘
59.
Which of the following statements is valid?
多选题 (2 分) 2 分
- A.
double d[] = new double[30];
- B.
char[] c = new char();
- C.
int[] i = {3, 4, 3, 2};
- D.
char[] c = new char[4]{'a', 'b', 'c', 'd'};
- E.
int i = new int(30);
73.
Analyze the following code:
public class Test1 {
public static void main(String[] args) {
xMethod(new double[]{3, 3});
xMethod(new double[5]);
xMethod(new double[3]{1, 2, 3});
}
public static void xMethod(double[] a) {
System.out.println(a.length);
}
}
单选题 (1 分) 1 分
- A.
The program has a compile error because xMethod(new double[3]{1, 2, 3}) is incorrect.
- B.
The program has a compile error because xMethod(new double[]{3, 3}) is incorrect.
- C.
The program has a runtime error because a is null.
- D.
The program has a compile error because xMethod(new double[5]) is incorrect.
Assume int[] scores = {1, 20, 30, 40, 50}, what is the output of System.out.println(java.util.Arrays.toString(scores))?
单选题 (1 分) 1 分
- A.
{1 20 30 40 50}
- B.
{1, 20, 30, 40, 50}
- C.
[1 20 30 40 50]
- D.
[1, 20, 30, 40, 50]
79.
The arraycopy method does not allocate memory space for the target array. The target array must already be created with memory space allocated.
判断题 (2 分) 2 分
- A.
true
- B.
false