Skip to content
Sharp

Core Java · interview question

Given two products with prices stored as doubles, how can you ensure accurate total price calculation?

Multiple choiceHardchapter-1-curatedpremiumcore-javanumeric-types-and-money-basics
Choose one answer
Answer and explanation

Correct answer

B. Use BigDecimal for both prices

Why

Using BigDecimal for both prices ensures precision and avoids the inaccuracies of floating-point arithmetic prevalent in double calculations.

Test yourself on Core Java

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

Start free test
All Core Java questions →