Java Data Type How to - Is a Float Infinite








Question

We would like to know how to is a Float Infinite.

Answer

  /* w w  w.  jav  a  2s  .  com*/



public class Main {
  public static void main(String[] args) {
    float f = (float) 1 / 0;
    boolean b1 = Float.isInfinite(f);
    System.out.println(b1);

    Float fObj = new Float(f);
    boolean b2 = fObj.isInfinite();
    System.out.println(b2);
  }
}

The code above generates the following result.