Java.lang Package Classes

Java Double - isNaN() Method



The java.lang.Double.isNaN() method is used to check whether the specified number is a Not-a-Number (NaN) or not. The method returns true if the specified number is a Not-a-Number (NaN), false otherwise.

Syntax

public static boolean isNaN(double v)

Parameters

v Specify the value to be tested.

Return Value

Returns true if the argument is NaN; false otherwise.

Exception

NA.

Example:

In the example below, the java.lang.Double.isNaN() method is used to check whether the given number is NaN or not.

import java.lang.*;

public class MyClass {
  public static void main(String[] args) {
    
    //creating double values
    double x = 5.2;
    double y = 0.0/0.0;
    double z = Double.NaN;

    //checking double values for NaN
    System.out.println("Is x NaN?: " + Double.isNaN(x));  
    System.out.println("Is y NaN?: " + Double.isNaN(y)); 
    System.out.println("Is z NaN?: " + Double.isNaN(z));  
  }
}

The output of the above code will be:

Is x NaN?: false
Is y NaN?: true
Is z NaN?: true

❮ Java.lang - Double