+ 1

Anyone can explain how dose it work briefly.

public class Program { public static void main(String[] args) { int[] a = {1,2,3,4,1}; for(int n:a) { a[n] = 0; System.out.println(n); } } } O/p: 1 0 3 0 1

20th Aug 2019, 7:09 PM
Krishnanshu Dey
Krishnanshu Dey - avatar
3 odpowiedzi
+ 2
It's changing the elements of the array: a[1] = 0 Outputs n -> 1 a[2] = 0 Outputs n -> 0 ( set in the previous step) a[3] = 0 Outputs n -> 3 a[4] = 0 Outputs n -> 0 ( set in the previous step) a[1] = 0 Outputs n -> 1.
20th Aug 2019, 7:19 PM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar
+ 1
Krishnanshu Dey , you are welcome 😉
20th Aug 2019, 7:24 PM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar
0
Yaa I got it thanks
20th Aug 2019, 7:23 PM
Krishnanshu Dey
Krishnanshu Dey - avatar