Please, explain me step by step output of this code:
public class My {
public static void main(String[] args) {
int[] a = {1,2,3,4,1};
for (int n : a) {
a[n] = 0;
}
for (int n : a) {
System.out.println(n);
}
}
}
I know that is an enhanced loop. But do not understand how it works with a[n]=0
Why this code outputs 00301?