Java Float isNaN() Method

Java 8Object Oriented ProgrammingProgramming

The isNan() method returns true if the Float value is a Not-a-Number (NaN). Let’s say we have the following Float values.

Float f1 = new Float(5.0/0.0);
Float f2 = new Float(10.2/0.0);
Float f3 = new Float(0.0/0.0);

Check with isNaN() method.

f1.isNaN ();
f2.isNaN ();
f3.isNaN ();

The following is the complete example with output.

Example

 Live Demo

import java.lang.*;
public class Demo {
   public static void main(String args[]) {
      Float f1 = new Float(5.0/0.0);
      Float f2 = new Float(10.2/0.0);
      Float f3 = new Float(0.0/0.0);
      System.out.println(f1.isNaN());
      System.out.println(f2.isNaN());
      System.out.println(f3.isNaN());
      System.out.println(f1.isInfinite());
      System.out.println(f2.isInfinite());
      System.out.println(f3.isInfinite());
   }
}

Output

false
false
true
true
true
false
raja
Published on 10-Dec-2018 08:31:48
Advertisements