Question 1
What is the 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++)
for (int i = 0; i < list.length; i++)
| System.out.print(list[i] + " "); |
}
}
◦ 2 3 4 5 6 1
◦ 1 1 1 1 1 1
◦ 1 2 3 4 5 6
◦ 2 3 4 5 6 6
Question 2
In the following code, what is the printout for list2?
class Test {
public static void main(String[] args) {
| int[] list1 = {1, 2, 3}; |
| int[] list2 = {1, 2, 3}; |
| list1[0] = 0; list1[1] = 1; list2[2] = 2; |
| for (int i = 0; i < list2.length; i++) |
| System.out.print(list2[i] + " "); |
}
}
◦ 0 1 3
◦ 1 1 1
◦ 0 1 2
◦ 1 2 3