Double isNaN() method in Java

Java 8Object Oriented ProgrammingProgramming

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
raja
Published on 11-Dec-2018 06:12:30
Advertisements