adplus-dvertising
frame-decoration

Question

What is the output of below code snippet?
   double a = 0.02;
   double b = 0.03;
   double c = b - a;
   System.out.println(c);
 
   BigDecimal _a = new BigDecimal("0.02");
   BigDecimal _b = new BigDecimal("0.03");
   BigDecimal _c = b.subtract(_a);
   System.out.println(_c);

a.

0.009999999999999998
0.01

b.

0.01
0.009999999999999998

c.

0.01
0.01

d.

0.009999999999999998
0.009999999999999998

Posted under Java Programming

Answer: (a).0.009999999999999998
0.01

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?

Similar Questions

Discover Related MCQs

Q. What is the base of BigDecimal data type?

Q. What is the limitation of toString() method of BigDecimal?

Q. Which of the following is not provided by BigDecimal?

Q. BigDecimal is a part of which package?

Q. What is BigDecimal.ONE?

Q. Which class is a library of functions to perform arithmetic operations of BigInteger and BigDecimal?

Q. Which of these is long data type literal?

Q. Which of these can be returned by the operator &?

Q. Literals in java must be appended by which of these?

Q. Literal can be of which of these data types?

Q. Which of these can not be used for a variable name in Java?

Q. Which of these is necessary condition for automatic type conversion in Java?

Q. What is the prototype of the default constructor of this class?

public class prototype { }

Q. If an expression contains double, int, float, long, then the whole expression will be promoted into which of these data types?

Q. What is Truncation is Java?

Q. Which of these operators is used to allocate memory to array variable in Java?

Q. Which of these is an incorrect array declaration?

Q. Which of these is an incorrect Statement?

Q. Which of these is necessary to specify at time of array initialization?

Q. Generics does not work with?