Are you taking CLEP classes? Try clep.ai
| preferred AP College board partner for AP classes
AP Computer Science A/Unit 2: Using Objects
Start Practice TestPractice Test
About Exam
medium Solved by 1 students

Analyzing Integer Overflow in Java

< Prev
Next >

Consider the following method, which is intended to calculate compound interest.

public static int calculateCompoundInterest(int principal, int rate, int years) {
    int amount = principal;
    for (int i = 0; i < years; i++) {
        amount = amount + (amount * rate / 100);
    }
    return amount - principal;
}

Which of the following input scenarios is most likely to cause an integer overflow, leading to an incorrect result? An overflow can occur during any intermediate calculation within the loop.

A

principal = 100, rate = 5, years = 10

B

principal = 50000, rate = 8, years = 15

C

principal = 10000, rate = 3, years = 20

D

principal = 100000000, rate = 25, years = 15

Hint
Did You Know?
Explain Why
Explain All Answers
Check Answer
Show Correct Answer
Report Question
Mark for review

Question Leaderboard

Not enough data yet to show leaderboard.

No comments yet. Be the first to comment!

AI Tutor

How can I help?

APFIVE © 2020.
Email: apfive@apfive.org|Privacy Policy|