Java Double example to check whether the given number is a valid number using isNaN


public boolean isNaN()
Returns true if this Double value is a Not-a-Number (NaN), false otherwise.

Program:
package com.candidjava;

public class DoubleIsNaN 
{
   public static void main(String[] args) 
  {
     Double d1 = new Double(-1.0/0.0);
     Double d2 = new Double(0.0/0.0);
  
     // returns true if this Double value is a Not-a-Number (NaN) 
     System.out.println(d1 + " = " + d1.isNaN());  
     // returns false for other cases
     System.out.println(d2 + " = " + d2.isNaN());
   }
}  

Output:
-Infinity = false
NaN = true

Description:
      This method returns true if the value represented by this object is NaN; false otherwise.

Returns:
true if the value represented by this object is NaN; false otherwise.


Related Post

Comments


©candidjava.com