How to Check If a Number Is NaN in Java


In this example, we will learn how to check if a number is NaN in Java.

Source Code

package com.beginner.examples;

public class IsNaN {

  public static void main(String[] args) {
    Double num = new Double(0.0 / 0.0);
    System.out.println(num.isNaN()); // check if a number is NaN
  }
}

Output:

true
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments