java.lang.Double isNaN()
Syntax:
public boolean isNaN()
Java Code Example :
This java example source code demonstrates the use of isNaN() method of Double class. This method Returns true if this Double value is a Not-a-Number (NaN), 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 * isNaN() method of Double class */ public class DoubleIsNan { public static void main(String[] args) { // initiatlize the variables to be checked Double value1 = 125.32 / 0.0; Double value2 = -100.0 / 0.0; Double value3 = 25.112; Double value4 = 0.0 / 0.0; Double value5 = value1 / value2; // check if values are not a number System.out.println(value1 + " is not a number?" + value1.isNaN()); System.out.println(value2 + " is not a number?" + value2.isNaN()); System.out.println(value3 + " is not a number?" + value3.isNaN()); System.out.println(value4 + " is not a number?" + value4.isNaN()); System.out.println(value5 + " is not a number?" + value5.isNaN()); } }
Sample Output :
Running the above example source code will give the following output
Infinity is not a number?false -Infinity is not a number?false 25.112 is not a number?false NaN is not a number?true NaN is not a number?true