Hurry! Try our new Interactive Courses for FREE. 🥳   🚀

Java Double isInfinite() method

Java isInfinite() method is a part of the Double class of the java.lang package. This method is the exact opposite of the isFinite() method and is used to check whether the passed double value is an infinite value or not. It returns the boolean value false for finite double values and true for NaN,infinite values and values with very high magnitude.

Syntax:

public boolean isInfinite()  

Parameters:

No parameters are passed in this method.

Returns:

Returns false if the passed double value has a finite value and returns true for infinite, NaN, and extremely large double values.

Example 1:

Here, the boolean values are returned in accordance with the double value passed as an argument.

import java.lang.Double;
public class StudyTonight
{  
    public static void main(String[] args) 
    {  
        Double d1 = 528648.67;  
        Double d2 = d1/0.0; 
        Double d3 = -d1/0.0;
        Double d4 = 0.0/0.0;

        System.out.println("The value is : " +d1.isInfinite()); //returns false for finite value  
        System.out.println("The value is : " +d2.isInfinite()); //returns true for infinite value 
        System.out.println("The value is : " +d3.isInfinite()); //returns true for infinite value 
        System.out.println("The value is : " +d4.isInfinite()); // returns false for finite value               
    }  
}    


The value is : false
The value is : true
The value is : true
The value is : false

Example 2:

Here is a user-defined example where anyone using this code can put a value of his choice and get the equivalent output.

import java.lang.Double;
import java.util.Scanner;
public class StudyTonight
{  
    public static void main(String[] args) 
    {  
        try
        {
           System.out.println("Enter the value");
           Scanner sc = new Scanner(System.in);
           double d = sc.nextDouble();
           Double i = d;
          
           boolean b = i.isInfinite();
           if(b== true)
           {
              System.out.println("Value is infinite");
           }
           else
           {
              System.out.println("Value is finite");
           }
         }        
         catch(Exception e)
         {
            System.out.println("Invalid Input");
         }       
     }
}  


Enter the value
73389E85689
Value is infinite
******************
Enter the value
906.57
Value is finite
*****************
Enter the value
0x690
Invalid Input

Live Example:

Here, you can test the live code example. You can execute the example for different values, even can edit and write your examples to test the Java code.