Given: What is the result?
A.
10, 20, 30, 10, 20, 30
B.
12, 22, 32, 12, 22, 32
C.
11, 21, 31, 11, 21, 31
D.
11, 21, 31, 12, 22, 32
Given: What is the result?
A.
10, 20, 30, 10, 20, 30
B.
12, 22, 32, 12, 22, 32
C.
11, 21, 31, 11, 21, 31
D.
11, 21, 31, 12, 22, 32
B
doChange(arr[0],arr[1],arr[2]);==> I think it cannot compile
This question is wrong. The correct answer is “Compilation fails”
Compilation fails
public class Test3 {
public static void doChange(int[] arr) {
for(int pos = 0; pos < arr.length; pos++) {
arr[pos] = arr[pos] + 1;
}
}
public static void main(String[] args) {
int arr[] = {10, 20, 30};
doChange(arr);
for(int x : arr)
System.out.println(x);
doChange(arr[0], arr[1], arr[2]); // does not compile
for(int x : arr)
System.out.println(x);
}
it does not compile, if changed so that it compiles the answer is D