Java Double - isNaN() Method
The java.lang.Double.isNaN() method is used to check whether this Double value is a Not-a-Number (NaN) or not. The method returns true if this Double value is a Not-a-Number (NaN), false otherwise.
Syntax
public boolean isNaN()
Parameters
No parameter is required.
Return Value
Returns true if the value represented by this object is NaN; false otherwise.
Exception
NA.
Example:
In the example below, the java.lang.Double.isNaN() method is used to check whether the given Double value is NaN or not.
import java.lang.*; public class MyClass { public static void main(String[] args) { //creating Double value 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?: " + x.isNaN()); System.out.println("Is y NaN?: " + y.isNaN()); System.out.println("Is z NaN?: " + z.isNaN()); } }
The output of the above code will be:
Is x NaN?: false Is y NaN?: true Is z NaN?: true
❮ Java.lang - Double