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
- Bcheck_circle
26
- C
21
- D
16
Explanation
Sum of all elements: 2+5+8+11 = 26.
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?
11
26
21
16
Explanation
Sum of all elements: 2+5+8+11 = 26.
Want 10 more like this — adaptive to your weak spots?