题目内容

Analyze the following code: public class Test { public static void main(String[] args) { int[] x = new int[5]; for (int i = 0; i < x.length; i++)x[i] = i;System.out.println(x[i]);} }

A. The program displays 4.
B. The program has a syntax error because i is not defined in the last statement in the main methoD.
C. The program has a runtime error because the last statement in the main method causes ArrayIndexOutOfBounds exception.
D. The program displays 0 1 2 3 4.

查看答案
更多问题

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.

答案查题题库