int total = 0;
for (int i = 10; i >= 1; i--) {
total += i;
}
System.out.println(total);What is printed?
- Acheck_circle
55
- B
45
- C
10
- D
50
Explanation
The loop adds 10+9+8+...+1 = 55 to total.
AP Computer Science A· difficulty 2/5
int total = 0;
for (int i = 10; i >= 1; i--) {
total += i;
}
System.out.println(total);What is printed?
55
45
10
50
Explanation
The loop adds 10+9+8+...+1 = 55 to total.
Want 10 more like this — adaptive to your weak spots?