aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes NAN Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "NAN" Watch "NAN" New topic
Author

NAN

Sadashiv Borkar
Ranch Hand

Joined: Jun 07, 2000
Posts: 49
hi guys,
I got this question in one of the mock exams..
public class NanTest
{
public static void main(String[] args)
{
Double d1 = new Double(Double.NaN);
Double d2 = new Double(Double.NaN);
if(Double.NaN == Double.NaN)
System.out.println("Nan is True");
else
System.out.println("Nan is False");

if(d1.equals(d2))
System.out.println("Nan Objects are True");
else
System.out.println("Nan Objects are False");
}
}
Answers
A)Nan is True Nan Objects are True
B)Nan is True Nan Objects are False
C)Nan is False Nan Objects are True
D)Nan is False Nan Objects are False
It asked what will be the output The answer comes as ( C ).
But according to me the answer should be ( D ) as NaN is not a number so it should be false in both the cases.
Can anyone tell me what is the reason behind the ( C ) answer .
Thanks in advance.....
byeee

------------------
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
hi
the api states this in this regard
If d1 and d2 both represent Double.NaN, then the equals method returns true, even though Double.NaN==Double.NaN has the value false.
regds.
Rahul
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: NAN
 
Similar Threads
Question for Dan Wrapper Class
about == equals
Majji question - NaN
Double.NaN
pls help on NaN