double d = 0.1 + 0.2;
System.out.println(d == 0.3);What is printed?
- A
0.3
- B
Error
- C
true
- Dcheck_circle
false
Explanation
Floating-point arithmetic is not always exact; 0.1 + 0.2 produces a result slightly off from 0.3, so == returns false.
AP Computer Science A· difficulty 4/5
double d = 0.1 + 0.2;
System.out.println(d == 0.3);What is printed?
0.3
Error
true
false
Explanation
Floating-point arithmetic is not always exact; 0.1 + 0.2 produces a result slightly off from 0.3, so == returns false.
Want 10 more like this — adaptive to your weak spots?