How to Check If a Number Is Infinite in Java


In this example we will show how to check if a number is infinite in Java.

Source Code

package com.beginner.examples;

public class IsInfinite {

  public static void main(String[] args) {
    Double num = new Double(2.0 / 0);
    System.out.println(num.isInfinite()); // check if a number is infinite
  }
}

Output:

true
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments