0

What is the output of this code?

ArrayList<Integer> list = new ArrayList<Integer>(); for (int i = 0; i < 6; i++) { list.add(i); } int x = 0; Iterator<Integer> it = list.iterator(); while (it.hasNext()) { x+= it.next(); } System.out.println(x);

2nd May 2019, 2:00 AM
Ajeet Kumar Prasad
Ajeet Kumar Prasad - avatar
6 odpowiedzi
+ 11
It's the sum of numbers from 0 to 5 = 15
2nd May 2019, 5:42 AM
Javier Felipe Toribio
Javier Felipe Toribio - avatar
+ 6
Code Playground has the answer.
2nd May 2019, 2:00 AM
Diego
Diego - avatar
0
15
19th Dec 2021, 3:05 PM
Pawani Ishanka
Pawani Ishanka - avatar
0
15
1st Jan 2022, 12:37 PM
M.I.M.Aqueel
M.I.M.Aqueel - avatar
0
15
5th Jul 2022, 7:46 AM
Antenhe Yimer
0
15
8th Dec 2022, 12:07 PM
Prince Kumar
Prince Kumar - avatar