Double isNaN() method in Java


The java.lang.Double.isNan() method returns true if the specified number is a Not-a-Number (NaN) value, false otherwise.

Let’s say the following are our Double values.

Double val1 = new Double(3/0.);
Double val2 = new Double(0/0.);

Now, we will use the isNan() method to check whether the number is a NaN or not.

val1.isNaN();
val2.isNaN()

The following is our final example.

Example

 Live Demo

public class Demo {
   public static void main(String args[]) {
      Double val1 = new Double(3/0.);
      Double val2 = new Double(0/0.);
      System.out.println(val1.isNaN());
      System.out.println(val2.isNaN());
   }
}

Output

false
true

karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know

Updated on: 26-Jun-2020

106 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements