Java Double example to check whether the given number is a infinite using isInfinite


public boolean isInfinite()
Returns true if this Double value is infinitely large in magnitude, false otherwise.

Program;
package com.candid;

public class DoubleIsInfinite 
{
   public static void main(String[] args) 
  {
     Double d1 = new Double(1.0/0.0);
     Double d2 = new Double(0.0/0.0);
  
     // returns true if positive or negative infinity
     System.out.println(d1 + " = " + d1.isInfinite());  
     // returns false for other cases
     System.out.println(d2 + " = " + d2.isInfinite());
   }
}  

Output:
Infinity = true
NaN = false

Description:
      This method returns true if the value represented by this object is positive infinity or negative infinity, else false.

Returns:
true if the value represented by this object is positive infinity or negative infinity; false otherwise.


Related Post

Comments


©candidjava.com