+ 1
Who can explain this code to me?
Who can help me about this code? How does this code work? int [] a = {1,2,3,4,1}; for(int n: a){ a[n]=0;} for(int n: a){System.out.println(n);}
1 Answer
+ 7
This happens inside enhanced for loop:
{1,2,3,4,1}
n=1
a[1]=0 {1,0,3,4,1}
n=0
a[0]=0 {0,0,3,4,1}
n=3
a[3]=0 {0,0,3,0,1}
n=0
a[0]=0 {0,0,3,0,1}
n=1
a[1]=0 {0,0,3,0,1}