Discussion Forum

  1. Home
  2. »
  3. Languages
  4. »
  5. What is the output of...
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);
 }
}

Compilation failure

Add: 684.66 Add using MathContext: 6.8E+2

Runtime exception

Add 6.8E+2 Add using MathContext: 684.66

Answer: B . Add: 684.66 Add using MathContext: 6.8E+2
0Shares
0 0

If you think the posted answer is wrong or Confused About the Answer? Ask for Details Here

Know Explanation? Add it Here
we’ll review your comment and contact you soon….

Leave a Reply

Your email address will not be published. Required fields are marked *

error: You are not allowed to do so.....
0Shares
0
Scroll to Top