• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

NAN

 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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

------------------
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
If somebody says you look familiar, tell them you are in porn. Or in these tiny ads:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic