1.
Suppose int[] list = {4, 5, 6, 2, 1, 0}, what is list[0]?
A. 
B. 
C. 
D. 
2.
Suppose int[] list = {4, 5, 6, 2, 1, 0}, what is list.length?
A. 
B. 
C. 
D. 
3.
What is the representation of the third element in an array called a?
A. 
B. 
C. 
D. 
4.
If you declare an array double[] list = {3.4, 2.0, 3.5, 5.5}, list[1] is ________.
A. 
B. 
C. 
D. 
5.
If you declare an array double[] list = {3.4, 2.0, 3.5, 5.5}, the highest index in array list is __________.
A. 
B. 
C. 
D. 
6.
Which of the following is incorrect?
A. 
B. 
C. 
D. 
E. 
7.
How many elements are in array double[] list = new double[5]?
A. 
B. 
C. 
D. 
8.
What is the correct term for numbers[99]?
A. 
B. 
C. 
D. 
9.
Public class Test {
public static void main(String[] args) {
int[] x = new int[3];
System.out.println("x[0] is " + x[0]);
}
}
A. 
The program has a compile error because the size of the array wasn't specified when declaring the array.
B. 
He program has a runtime error because the array element x[0] is not defined.
C. 
The program runs fine and displays x[0] is 0.
10.
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 compiles and runs fine and the output "Value is 2.0" is printed.
B. 
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}.
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[3]{1, 2, 3};
D. 
The program compiles and runs fine and the output "Value is 1.0" is printed.
11.
Which one do you like?
A. 
Char[2] charArray = {'a', 'b'};
B. 
Char[] charArray = {'a', 'b'};
C. 
Char[] charArray = new char[]{'a', 'b'};
D. 
Char[] charArray = new char[2]; charArray = {'a', 'b'};
12.
Select the ones you like
A. 
B. 
C. 
Double d[] = new double[30];
D. 
13.
Suppose int i = 5, which of the following can be used as an index for array double[] t = new double[100]?
A. 
B. 
(int)(Math.random() * 100))
C. 
D. 
14.
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. 
He program compiles and runs fine and the output "Value is 2.0" is printed.
B. 
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}.
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[3]{1, 2, 3};
D. 
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};
15.
Assume int[] t = {1, 2, 3, 4}. What is t.length?
A. 
B. 
C. 
D. 
16.
What is the output of the following code?
double[] myList = {1, 5, 5, 5, 5, 1};
double max = myList[0];
int indexOfMax = 0;
for (int i = 1; i < myList.length; i++) {
if (myList[i] > max) {
max = myList[i];
indexOfMax = i;
}
}
System.out.println(indexOfMax);
A. 
B. 
C. 
D. 
17.
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 has a runtime error because the last statement in the main method causes ArrayIndexOutOfBoundsException.
B. 
He program displays 0 1 2
C. 
D. 
The program has a compile error because i is not defined in the last statement in the main method.
18.
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 + " ");
}
}
A. 
The program displays 2.5, 3.0 4.0
B. 
The program displays 2.5 3.0 4.0
C. 
The program displays 2.5, 3, 4
D. 
The program has a syntax error because value is undefined.
19.
What is the output of the following code?
int[] myList = {1, 2, 3, 4, 5, 6};
for (int i = myList.length - 2; i >= 0; i--) {
myList[i + 1] = myList[i];
}
for (int e: myList)
System.out.print(e + " ");
A. 
B. 
C. 
D. 
20.
What is output of the following code:
public class Test {
public static void main(String[] args) {
int[] x = {120, 200, 016};
for (int i = 0; i < x.length; i++)
System.out.print(x[i] + " ");
}
}
A. 
B. 
C. 
016 is a compile error. It should be written as 16.
D. 
21.
What is output of the following code:
public class Test {
public static void main(String[] args) {
int list[] = {1, 2, 3, 4, 5, 6};
for (int i = 1; i < list.length; i++)
list[i] = list[i - 1];
for (int i = 0; i < list.length; i++)
System.out.print(list[i] + " ");
}
}
A. 
B. 
C. 
D. 
22.
In the following code, what is the output for list2?
public class Test {
public static void main(String[] args) {
int[] list1 = {1, 2, 3};
int[] list2 = {1, 2, 3};
list2 = list1;
list1[0] = 0; list1[1] = 1; list2[2] = 2;
for (int i = 0; i < list2.length; i++)
System.out.print(list2[i] + " ");
}
}
A. 
B. 
C. 
D. 
23.
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 < x.length; i++)
System.out.print(x[i] + " ");
}
}
A. 
The program displays 1 2 3 4
B. 
The program has a compile error on the statement x = new int[2], because x is final and cannot be changed.
C. 
D. 
The elements in the array x cannot be changed, because x is final.
24.
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 can compile and run fine. The second line assigns a new array to list.
C. 
The code has compile errors because you cannot assign a different size array to list.
D. 
The code has runtime errors because the variable list cannot be changed once it is assigned.
25.
Analyze the following code:
public class Test {
public static void main(String[] args) {
int[] a = new int[4];
a[1] = 1;
a = new int[2];
System.out.println("a[1] is " + a[1]);
}
}
A. 
The program has a compile error because new int[2] is assigned to a.
B. 
He program has a runtime error because a[1] is not initialized.
C. 
The program displays a[1] is 0.
D. 
The program displays a[1] is 1.