Question 1
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 + " "); |
◦ 1 2 3 4 5 6
◦ 6 1 2 3 4 5
◦ 2 3 4 5 6 1
◦ 6 2 3 4 5 1
◦ 1 1 2 3 4 5
Question 2
What is the 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] + " "); |
}
}
◦ 120 200 14
◦ 120 200 16
◦ 120 200 20
◦ 016 is a compile error. It should be written as 16.