Home » JAVA Programming » Basic Datatypes » Question
  1. What is the output of below code snippet?

    public class Output
    {
    public static void main(String args[])
    {
    BigDecimal z = new BigDecimal("23.43");
    BigDecimal br = new BigDecimal("24");
    BigDecimal bres = z.add(new BigDecimal("450.23"));
    System.out.println("Add: "+bres);

    MathContext mc = new MathContext(2, RoundingMode.DOWN);
    BigDecimal bdecMath = z.add(new BigDecimal("450.23"), mc);
    System.out.println("Add using MathContext: "+bdecMath);
    }
    }
    1. Compilation failure
    2. Runtime exception
    3. Add: 684.66
      Add using MathContext: 6.8E+2
    4. Add 6.8E+2
      Add using MathContext: 684.66
    5. None of these
Correct Option: C

add() adds the two numbers, MathContext provides library for carrying out various arithmetic operations.



Your comments will be displayed only after manual approval.