Traversing Arrays

AP Computer Science A· difficulty 2/5

int[] a = {2, 5, 8, 11};
int i = 0;
int sum = 0;
while (i < a.length) {
  sum += a[i];
  i++;
}
System.out.println(sum);

What is printed?

  • A

    11

  • B

    26

    check_circle
  • C

    21

  • D

    16

Explanation

Sum of all elements: 2+5+8+11 = 26.

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

Related questions

AP Computer Science A · Traversing Arrays Practice Question | Acemy