int[] a = {5, 3, 8, 1};
int total = 0;
for (int x : a) {
total += x;
}
System.out.println(total);What is printed?
- Acheck_circle
17
- B
16
- C
15
- D
1
Explanation
The enhanced for-loop visits every element. 5+3+8+1 = 17.
AP Computer Science A· difficulty 2/5
int[] a = {5, 3, 8, 1};
int total = 0;
for (int x : a) {
total += x;
}
System.out.println(total);What is printed?
17
16
15
1
Explanation
The enhanced for-loop visits every element. 5+3+8+1 = 17.
Want 10 more like this — adaptive to your weak spots?