+ 5
Quiz Module 6
Question 5 of the 6th module's answer is 15, I don't understand why, because the condition is from i=0 to i<6. 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);
3 Respostas
+ 17
This code sums all the values of the list:
0+1+2+3+4+5=15
I added some explanatory comments to the code:
https://code.sololearn.com/c8JXn2fMS7AP/?ref=app
+ 11
You're welcome ^^
+ 9
@Tashi N's excellent explanation should be enough unless there's need for translation.
Thanks Tashi!