Java – How to check if a double value is Infinite ?


Grammarly

More than 40 Lakhs Students and Professionals use Grammarly for their spell and grammar checks. You can register and try for free.

Problem Statement

You need to find out if the given number of type double is Infinite or not.

Solution

Use the isInfinite method defined in the Double class to find of the given number is a infinite as shown below.

public class Main {

    public static void main(String[] args) {

        System.out.println("Abundantcode.com Java Tutorials");

        Double input1 = new Double(1/0.);
        System.out.println(input1.isInfinite());


    }
}

The output of the above program is

Abundantcode.com Java Tutorials

true


Grammarly

More than 40 Lakhs Students and Professionals use Grammarly for their spell and grammar checks. You can register and try for free.
%d bloggers like this: