Last Updated : 11 Jul, 2025
The
isNaN()method of
Java Double classis a built in method in Java returns true if this Double value or the specified double value is Not-a-Number (NaN), or false otherwise.
Syntax:
public boolean isNaN() or public static boolean isNaN(double val)Parameters
: The function accepts a single parameter
valwhich specifies the value to be checked when called directly with the Double class as static method. The parameter is not required when the method is used as instance method.
Return Value:It returns
trueif the val is
NaNelse it return
false. Below programs illustrate
isNaN()method in Java:
Program 1: Java
// Java code to demonstrate
// Double isNaN() method
// without parameter
class GFG {
public static void main(String[] args)
{
// first example
Double f1 = new Double(1.0 / 0.0);
boolean res = f1.isNaN();
// printing the output
if (res)
System.out.println(f1 + " is NaN");
else
System.out.println(f1 + " is not NaN");
// second example
f1 = new Double(0.0 / 0.0);
res = f1.isNaN();
// printing the output
if (res)
System.out.println(f1 + " is NaN");
else
System.out.println(f1 + " is not NaN");
}
}
Output:
Infinity is not NaN NaN is NaNProgram 2: Java
// Java code to demonstrate
// Double isNaN() method
// with parameter
class GFG {
public static void main(String[] args)
{
// first example
Double f1 = new Double(1.0 / 0.0);
boolean res = f1.isNaN(f1);
// printing the output
if (res)
System.out.println(f1 + " is NaN");
else
System.out.println(f1 + " is not NaN");
// second example
f1 = new Double(0.0 / 0.0);
res = f1.isNaN(f1);
// printing the output
if (res)
System.out.println(f1 + " is NaN");
else
System.out.println(f1 + " is not NaN");
}
}
Output:
Infinity is not NaN NaN is NaNReference: https://docs.oracle.com/javase/7/docs/api/java/lang/Float.html#isNaN()
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4