Developing Algorithms Using Arrays

AP Computer Science A· difficulty 2/5

int[] a = {3, 1, 4, 1, 5, 9, 2, 6};
int sum = 0;
for (int i = 2; i < 5; i++) sum += a[i];

What is sum?

  • A

    9

  • B

    8

  • C

    10

    check_circle
  • D

    11

Explanation

a[2]+a[3]+a[4] = 4+1+5 = 10.

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

Related questions