Skip to content
Sharp

Core Java · interview question

Identify the flaw in this code that calculates an order total with tax, where 'taxRate' is 0.1?

Multiple choiceHardchapter-1-curatedpremiumcore-javacode-reading-and-debugging
java
double orderTotal = 100;
double taxRate = 0.1;
orderTotal = orderTotal + taxRate;
Choose one answer
Answer and explanation

Correct answer

D. The total doesn't include the tax correctly.

Why

The calculation is flawed because 'orderTotal' should be multiplied by (1 + taxRate) to correctly add the tax. The current code attempts to add tax directly, which is incorrect.

Test yourself on Core Java

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

Start free test
All Core Java questions →