Analyze the following code: public class Test {public static void main(String[] args) {int[] oldList = {1, 2, 3, 4, 5};reverse(oldList);for (int i = 0; i < oldList.length; i++)System.out.print(oldList[i] + " ");} public static void reverse(int[] list) {int[] newList = new int[list.length]; for (int i = 0; i < list.length; i++)newList[i] = list[list.length - 1 - i]; list = newList;} }
A. The program displays 1 2 3 4 5 and then raises an ArrayIndexOutOfBoundsException.
B. The program displays 1 2 3 4 5.
C. The program displays 5 4 3 2 1.
D. The program displays 5 4 3 2 1 and then raises an ArrayIndexOutOfBoundsException.
查看答案
If a key is not in the list, the binarySearch method returns _________.
A. insertion point
B. insertion point - 1
C. -(insertion point + 1)
D. -insertion point
The name length is a method in an array.
A. false
B. true
In the following code, what is the printout for list2? class Test {public static void main(String[] args) {int[] list1 = {3, 2, 1};int[] list2 = {1, 2, 3};list2 = list1;list1[0] = 0; list1[1] = 1; list2[2] = 2; for (int i = list2.length - 1; i >= 0; i--)System.out.print(list2[i] + " ");} }
A. 0 1 2
B. 1 2 3
C. 2 1 0
D. 0 1 3.
Which code fragment would correctly identify the number of arguments passed via the command line to a Java application, excluding the name of the class that is being invoked?
A. int count = args.length - 1;
B. int count=0; while (!(args[count].equals(""))) count ++;
C. int count = 0; while (args[count] != null) count ++;
D. int count = args.length;