Traversing ArrayLists

AP Computer Science A· difficulty 4/5

Output:

<code>ArrayList<Integer> list = new ArrayList<>(); list.add(1); list.add(2); list.add(3); int s = 0; for (int x : list) s += x; System.out.println(s); </code></pre>

  • A

    9

  • B

    12

  • C

    6

    check_circle
  • D

    3

Explanation

Sum 1 + 2 + 3 = 6.

Want 10 more like this — adaptive to your weak spots?

Related questions