0
So Close, Yet So Far. (iterators, next, hasnext)
I am so close to finishing the Java course, but I cannot get past the 2nd to last question. The question: What does the following code output? 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); The Problem: I've gotten a few legitimate answers and I have plugged them in, but all of them were incorrect.
4 odpowiedzi
+ 10
This code adds the numbers 0 to 5 in a list and adds them, so you get 0 + 1 + 2 + 3 + 4 + 5 = 15.
+ 1
15
0
Nevermind. I got the answer.
0
15