Java Float isInfinite() Method

Java 8Object Oriented ProgrammingProgramming

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
raja
Published on 19-Dec-2018 06:04:32
Advertisements