For Loop Accumulator Variable
Consider the following code segment. What value is printed when the code is executed?
public class Savings {
public static void main(String[] args) {
int total = 0;
for(int day = 1; day <= 7; day++) {
total += day * 2;
}
System.out.println(total);
}
}
A
54
B
56
C
49
D
28
Question Leaderboard
| Rank | |||||
|---|---|---|---|---|---|
| #1 | hadleysmith5 | 2 | 2 | 0m 00s | 200 |
| #2 | hitrishabhatia | 1 | 1 | 0m 00s | 100 |
| #3 | sgarv2513 | 1 | 1 | 0m 00s | 100 |
| #4 | mertdeg | 1 | 4 | 0m 00s | 70 |
| #5 | y.seong2027 | 1 | 1 | 0m 44s | 56 |
| #6 | midnightasdark | 1 | 2 | 1m 43s | -13 |
| #7 | gtsak31 | 1 | 1 | 2m 50s | -70 |
| #8 | suhanakochhar006 | 1 | 1 | 9m 19s | -459 |
| #9 | Pelisx | 1 | 1 | 25m 55s | -1,455 |
Items per page:
10
1 – 9 of 9
APFIVE