Sunday, July 19, 2009

Puzzle 42 – Solution.

Nan is a special number having a unique property that one Nan is not equal to another Nan. In java a floating point variable can be assigned Nan as a value.

So, someType = float & someValue = Float.Nan or 0.0f/0.0f, gives you the desired result!

class Equals {
public static void main(String args[]){
float x = Float.NaN;
== x) //This prints false!!

No comments:

Post a Comment

Solution for this question?