Part IV: Multiple Choice Questions: (1 pts each)
(1. Mark your answers on the sheet. 2. Login and click Take
Instructor Assigned Quiz for Quiz3. 3. Submit it online
within 5 mins. 4. Close the browser.)
1 Analyze the following code.
public class Test {
public static void main(String[] args) {
int[] x = new int[3];
System.out.println(“x[0] is ” + x[0]);
}
#
2 Suppose
static void nPrint(String message, int n) {
while (n > 0) {
System.out.print(message);
n–;
}
}
What is the printout of the call nPrint(‘a’, 4)?
A. aaaaa
B. aaaa
C. invalid call, because ‘a’ is a character, not a string.
D. aaa
#
3 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, 4
b. The program displays 2.5 3 4
c. The program displays 2.5 3.0 4.0
d. The program displays 2.5, 3.0 4.0