Skip to Content

Java Double isInfinite example

  1. /*
  2.   Java Double isInfinite example
  3.   This example shows how to use isInfinite() method of the Double class.
  4. */
  5.  
  6. public class JavaDoubleIsInfiniteExample {
  7.  
  8.   public static void main(String[] args) {
  9.  
  10.     /*
  11.      boolean isInfinite(double) static method checks whether the agrument primitive
  12.      double value is infinite number or not.
  13.      It return true if the specified argument is infinite value, false otherwise.
  14.     */
  15.     double d = (double) 4/0;
  16.     boolean b1 = Double.isInfinite(d);
  17.     System.out.println(b1);
  18.  
  19.     /*
  20.      boolean isInfinite() instance method checks whether the Double object
  21.      is infinite number or not.
  22.      It return true if the object is infinite value, false otherwise.
  23.     */
  24.     Double dObj = new Double(d);
  25.     boolean b2 = dObj.isInfinite();
  26.     System.out.println(b2);
  27.  
  28.   }
  29. }
  30.  
  31. /*
  32. Output would be
  33. true
  34. true
  35. */