Basic Help........

class Sekhar

{

public static void main(String[] args)

{

Double a=new Double(Double.NaN);

Double b=new Double(Double.NaN);

if(Double.NaN == Double.NaN)

System.out.println("True");

else

System.out.println("False");

if(a.equals(b))

System.out.println("True");

else

System.out.println("False");

}

}

in the first if statement i am compareing same constants of Double class why program not printing True

[502 byte] By [un_sekhablea] at [2007-11-27 5:11:22]
# 1
1. Because NaN is not a number as a result of an invalid computation. 2. Because you have compared two reference variable that references the same constant which is Double.NaN
eadelarosaa at 2007-7-12 10:31:43 > top of Java-index,Java Essentials,Java Programming...
# 2
NaN stands for Not a Number0/100 -> x -> infinity0/0-> y-> infinitymathematically can you say as x=yyou cannot say x=y it is a falseboth values are not defined and you cannot say as both are equal
Suraweeraa at 2007-7-12 10:31:43 > top of Java-index,Java Essentials,Java Programming...
# 3

An NaN is NEVER equal to anything, even itself, and that is the way it is designed. If you don't believe it, then try the following and tell me what it produces:

double z = Double.NaN;

System.out.println(z);

System.out.println(z == z);

masijade.a at 2007-7-12 10:31:43 > top of Java-index,Java Essentials,Java Programming...