I was just studying OCPJP questions and I found this strange code:
public static void main(String a[]) {
System.out.println(Double.NaN==Double.NaN);
System.out.println(Double.NaN!=Double.NaN);
}
When I ran the code, I got:
false
true
How is the output false
when we're comparing two things that look the same as each other? What does NaN
mean?
NaN means "Not a Number".
Java Language Specification (JLS) Third Edition says: