Developing Algorithms Using Arrays

AP Computer Science A· difficulty 3/5

What's the sum after this loop?

<code>int[] arr = {3, 1, 4, 1, 5}; int sum = 0; for (int i = 0; i < arr.length; i++) sum += arr[i]; </code></pre>

  • A

    14

    check_circle
  • B

    13

  • C

    15

  • D

    20

Explanation

3 + 1 + 4 + 1 + 5 = 14.

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

Related questions