Java.lang.Double.isNan() Method

Advertisements


Description

The java.lang.Double.isNan(double v) method returns true if the specified number is a Not-a-Number (NaN) value, false otherwise.The argument v is the value to be tested.

Declaration

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

public static boolean isNaN(double v)

Parameters

  • v -- This is the value to be tested.

Return Value

This method returns true if the value of the argument 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(d1));
  
     // returns false for other cases
     System.out.println(d2 + " = " + d2.isNaN(d2));
   }
} 

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

-Infinity = false
NaN = true



Advertisements
Advertisements