Written by 7:51 am Technology

How To Represent Infinity In Java?

Infinity is a concept of being bigger than any other value. It can be represented in Java by using BigInteger class. BigInteger class is used to represent large integers.

java.math.BigInteger Class

The java.math package contains several classes related to mathematical functions, such as adding, multiplying and so on. The java.math package has been introduced in JDK 1.2 and its main class is BigInteger which represents an arbitrary-sized integer number (that is, any number that can fit into memory). The BigInteger class provides methods for signed and unsigned integer arithmetic including addition, subtraction, multiplication, division and square root operations as well as modulo operations.

The following code snippet shows how to represent infinity in java by using the BigInteger class:

(Visited 19 times, 1 visits today)

Last modified: October 1, 2022

Close