| preferred AP College board partner for AP classes
AP Computer Science A/Unit 4: Iteration
Start Practice Test
Share
medium Solved by 5 students
Java For Loop Code Tracing
< Prev
Next >

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

Hint
Did You Know?
Explain Why
Explain All Answers
Check Answer
Show Correct Answer

Question Leaderboard

Rank
User
Correct Count
Attempt Count
Time
Score
#1mertdeg11 0m 00s 100
#2hitrishabhatia11 0m 00s 100
#3sgarv251312 0m 00s 90
#4suhanakochhar00611 2m 15s -35
#5gtsak3111 5m 01s -201
#6y.seong202702 4m 07s -267
APFIVE © 2020.
Email: [email protected]|Privacy Policy