Java.lang.Double.isNan() Method

Advertisements


Description

The java.lang.Double.isNan() method returns true if this Double value is a Not-a-Number (NaN), false otherwise.

Declaration

Following is the declaration for java.lang.Double.isNan() method

public boolean isNaN()

Parameters

  • NA

Return Value

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

Exception

  • NA

Example

The following example shows the usage of java.lang.Double.isNan() method.

package com.tutorialspoint;

import java.lang.*;

public class DoubleDemo {

   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());
   }
}  

Let us compile and run the above program, this will produce the following result:

-Infinity = false
NaN = true



Advertisements
Advertisements