Java For Loop Code Tracing
Develop code for standard and original algorithms (without data structures) and determine the result of these algorithms.
A programmer is implementing an algorithm to calculate compound interest. Consider this code segment:
double principal = 1000.0;
double rate = 0.05;
int years = 3;
double amount = principal;
for (int i = 0; i < years; i++) {
amount = amount * (1 + rate);
}
System.out.println((int) amount);
What is printed as a result of executing this code segment?
A
1157
B
1200
C
1150
D
1158
Question Leaderboard
| Rank | |||||
|---|---|---|---|---|---|
| #1 | mertdeg | 1 | 1 | 0m 00s | 100 |
| #2 | hitrishabhatia | 1 | 1 | 0m 00s | 100 |
| #3 | sgarv2513 | 1 | 2 | 0m 00s | 90 |
| #4 | suhanakochhar006 | 1 | 1 | 2m 15s | -35 |
| #5 | gtsak31 | 1 | 1 | 5m 01s | -201 |
| #6 | y.seong2027 | 0 | 2 | 4m 07s | -267 |
APFIVE