Java Float isInfinite() Method


The Float.isInfinite() method in Java returns true if this Float value is infinitely large in magnitude, else false is returned.

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 isInfinite() method

f1.isInfinite();
f2.isInfinite();
f3.isInfinite();

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.isInfinite());
      System.out.println(f2.isInfinite());
      System.out.println(f3.isInfinite());
   }
}

Output

true
true
false

Updated on: 27-Jun-2020

77 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements