Skip to content
Sharp

Core Java · interview question

Given a total price as a BigDecimal, what is the best way to apply a 10% discount?

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

Correct answer

B. TotalPrice.subtract(totalPrice.multiply(new BigDecimal("0.1")))

Why

The subtract and multiply methods of BigDecimal should be used to apply the discount accurately. By multiplying the total by 0.1 and subtracting, you ensure precise arithmetic.

Test yourself on Core Java

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

Start free test
All Core Java questions →