Skip to content
Sharp

Core Java · interview question

What will be the result of the following code when calculating the total cost with a discount?

Multiple choiceMediumchapter-1-curatedpremiumcore-javanumeric-types-and-money-basics
java
double price = 100.0;
double discount = 0.1;
double totalCost = price - (price * discount);
Choose one answer
Answer and explanation

Correct answer

D. 89.99999999999999

Why

Due to the way floating-point arithmetic works in Java, using double for money can result in precision issues, such as 89.99999999999999 instead of an exact value.

Test yourself on Core Java

A free test with instant, explained results. No account needed.

Start free test
All Core Java questions →