0

I can't figured out how this java code worked

public class Program { 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); } } Output = 00301

19th Apr 2020, 5:08 PM
Musa M N
Musa M N - avatar
9 Answers
+ 3
Musa Muhammad Ndagie The loop is explained in the code below. Hope you understand it now. https://code.sololearn.com/c0pij3z7g868/?ref=app
19th Apr 2020, 5:46 PM
Avinesh
Avinesh - avatar
0
I understand it is an enhanced-for loop but I'm unable to figure out the logical steps it followed to get the output
19th Apr 2020, 5:28 PM
Musa M N
Musa M N - avatar
0
Thank you, I'll try it out
19th Apr 2020, 5:36 PM
Musa M N
Musa M N - avatar
0
OK thanks👍
19th Apr 2020, 5:39 PM
Musa M N
Musa M N - avatar