Java Float isNaN() Method



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
Updated on: 2020-06-26T08:04:00+05:30

192 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements