public class HelloWorld{
public static void main(String []args){
String[] array = {"0","1","2","3","4","5"};
int i = 0;
for(String v : array){
if (i % 2 == 0){
System.out.println(v);
}
i++;
}
}
}
You are not using just the enhanced for loop in your code. You are using iteration variable as well. That is the whole point of this question. Enhanced for loop does not have an iteration variable.
That is the whole point of this question. Enhanced for loop does not have an iteration variable. Otherwise, all loops are interchangeable. What you can do with one loop, you can do with another.
You might want to add something to the effect of "without any additional code other than the loop and it's body", because you could use a stream to reverse the array or filter out odd objects before using the enhanced for-loop to achieve all 3.