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

    double d = 0.02;
    double e = 0.03;
    double f = e - d;
    System.out.println(c);

    BigDecimal _d = new BigDecimal("0.02");
    BigDecimal _e = new BigDecimal("0.03");
    BigDecimal _f = b.subtract(_d);
    System.out.println(_f);
    1. 0.01
      0.009999999999999998
    2. 0.01
      0.01
    3. 0.009999999999999998
      0.009999999999999998
    4. 0.009999999999999998
      0.01
    5. None of these
Correct Option: D

BigDecimal provides more precision as compared to double. Double is faster in terms of performance as compared to BigDecimal.



Your comments will be displayed only after manual approval.