Skip to content
Sharp

Core Java · interview question

Given the following code snippet, what output should you expect?

Multiple choiceMediumchapter-1-curatedpremiumcore-javanumeric-types-and-money-basics
java
BigDecimal price = new BigDecimal("1");
BigDecimal roundedPrice = price.setScale(2);
System.out.println(roundedPrice);
Choose one answer
Answer and explanation

Correct answer

C. 1.00

Why

The BigDecimal setScale method rounds the number to two decimal places, resulting in '1.00'.

Test yourself on Core Java

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

Start free test
All Core Java questions →