Check if a Double value is not-a-number with isNaN method in Java
Description
The following code shows how to check if a Double value is not-a-number with isNaN method.
Example
//from www . j a va 2 s. c o m
public class Main {
public static void main(String[] args) {
double d = Math.sqrt(-10);
boolean b1 = Double.isNaN(d);
System.out.println(b1);
Double dObj = new Double(d);
boolean b2 = dObj.isNaN();
System.out.println(b2);
}
}
The code above generates the following result.
Home »
Java Tutorial »
Java Data Type »
Java Tutorial »
Java Data Type »