0
Why this problem print 0 0 3 0 1?
int[] a = {1, 2, 3, 4, 1}; for(int n:a) a[n]=0; for(int n:a) System.out.println(n);
1 Resposta
+ 3
It loops through the array values, not indexes.
First step:
n=1;
a[1]=0;
[1, 0, 3, 0 1]
Second step:
n=0;
a[0]=0;
[0, 0, 3, 0, 1]
And so on