java.lang.Double isNaN(double v)
Syntax:
public static boolean isNaN(double v)
Java Code Example :
This java example source code demonstrates the use of isNaN(double v) method of Double class. This method returns true if the specified number is a Not-a-Number (NaN) value, false otherwise.
On this example we will evaluate numbers and check if the input is a number or not.
package com.javatutorialhq.java.examples;
/*
* This example source code demonstrates the use of static method
* isNaN(double v) of Double class
*/
public class DoubleIsNan {
public static void main(String[] args) {
double value1 = 100.0 / 0.0;
double value2 = -100.0 / 0.0;
double value3 = 300;
double value4 = 0.0 / 0.0;
double value5 = value1 / value2;
System.out.println(value1 + " is not a number?" + Double.isNaN(value1));
System.out.println(value2 + " is not a number?" + Double.isNaN(value2));
System.out.println(value3 + " is not a number?" + Double.isNaN(value3));
System.out.println(value4 + " is not a number?" + Double.isNaN(value4));
System.out.println(value5 + " is not a number?" + Double.isNaN(value5));
}
}
Sample Output :
Running the above example source code will give the following output
