Q. What will be the output of the following Java code snippet?
public class AddDemo
{
public static void main(String args[])
{
BigDecimal b = new BigDecimal("23.43");
BigDecimal br = new BigDecimal("24");
BigDecimal bres = b.add(new BigDecimal("450.23"));
System.out.println("Add: "+bres);

MathContext mc = new MathContext(2, RoundingMode.DOWN);
BigDecimal bdecMath = b.add(new BigDecimal("450.23"), mc);
System.out.println("Add using MathContext: "+bdecMath);
}
}

  • (A) Compilation failure
  • (B) Add: 473.66 Add using MathContext: 4.7E+2
  • (C) Add 4.7E+2 Add using MathContext: 473.66
  • (D) Runtime exception
πŸ’¬ Discuss
βœ… Correct Answer: (B) Add: 473.66 Add using MathContext: 4.7E+2

You must be Logged in to update hint/solution

πŸ’¬ Discussion


πŸ“Š Question Analytics

πŸ‘οΈ
111
Total Visits
πŸ“½οΈ
1 y ago
Published
πŸŽ–οΈ
Gopal Sharma
Publisher
πŸ“ˆ
86%
Success Rate