adplus-dvertising
frame-decoration

Question

What is the output of below 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: 684.66
Add using MathContext: 6.8E+2

c.

Runtime exception

d.

Add 6.8E+2
Add using MathContext: 684.66

Posted under Java Programming

Answer: (b).Add: 684.66
Add using MathContext: 6.8E+2

Engage with the Community - Add Your Comment

Confused About the Answer? Ask for Details Here.

Know the Explanation? Add it Here.

Q. What is the output of below code snippet?