JavaChallenge38
Published in
Sep 16, 2021
1. 1
2. 0.9999999999999999
3. 1.0000000000000001
4. 0.9999999999999999D
Try to solve the challenge by yourself first.
The answer should be 1
but that’s not the case the answer is 0.9999999999999999
. Let’s see the bytecode —
public class JavaChallenge38 {
public JavaChallenge38() {
}
public static void main(String[] args) {
System.out.println(0.9999999999999999D);
}
}
So, at compile time only all 0.1
will be added, but it’s weird; so many of you will get a question —
Is floating point math broken???
Please go through the following links, it will help you to understand the entire concept —
Thanks. Don’t forget to upvote.