For Loop Accumulator Variable
A savings plan simulation deposits an amount equal to twice the day number for 7 days. What total amount is printed at the end?
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
28
D
49
Question Leaderboard
| Rank | |||||
|---|---|---|---|---|---|
| #1 | hadleysmith5 | 2 | 2 | 0m 00s | 200 |
| #2 | sgarv2513 | 1 | 1 | 0m 00s | 100 |
| #3 | hitrishabhatia | 1 | 1 | 0m 00s | 100 |
| #4 | mertdeg | 1 | 4 | 0m 00s | 70 |
| #5 | y.seong2027 | 1 | 1 | 0m 44s | 56 |
| #6 | gtsak31 | 1 | 1 | 2m 50s | -70 |
| #7 | suhanakochhar006 | 1 | 1 | 9m 19s | -459 |
APFIVE