Who can explain this code to me? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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);}

23rd Jul 2019, 5:57 PM
Amir01
Amir01 - avatar
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}
23rd Jul 2019, 6:13 PM
voja
voja - avatar