Hi..
Question 12 says
1. class Loopy {
2. public static void main(
String[] args) {
3. int[] x = {7,6,5,4,3,2,1};
4. // insert code here
5. System.out.print(y + " ");
6. }
7. }
8. }
Which, inserted independently at line 4, compiles? (Choose all that apply.)
A. for(int y : x) {
B. for(x : Int y) {
C. int y = 0; for(y : x) {
D. for(int y=0, z=0; z<x.length; z++) { y = x[z];
E. for(int y=0, int z=0, int z=0; z<x.length; z++) { y = x[z];
F. int y = 0; for(int z=0; z<x.length; z++) { y = x[z];
the answer given is ADE whereas the following code does not compile
class Loopy {
public static void main(String[] args) {
int[] x = {7,6,5,4,3,2,1};
// insert code here
for(int y=0, int z=0, int z=0; z<x.length; z++) { y = x[z];
System.out.print(y + " ");
}
}
}
Can anyone explain why is it given as the right answer when it does not compile?