Skip to content
Sharp

Core Java · interview question

You have two BigDecimal values: a = new BigDecimal("0.1") and b = new BigDecimal("0.10"). What is the result of a.compareTo(b)?

Multiple choiceHardchapter-7-curatedpremiumcore-javabigdecimal-and-money
Choose one answer
Answer and explanation

Correct answer

C. 0

Why

The compareTo method compares the numeric values of two BigDecimal instances without considering their scale. Since 0.1 and 0.10 are numerically equal, compareTo returns 0.

Test yourself on Core Java

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

Start free test
All Core Java questions →