We can use the max() method of the BigInteger class to get the maximum value of the two BigInteger values.
Java BigInteger max value
We can use the max() method of the BigInteger class to get the maximum value of the two BigInteger values. It returns the BigInteger value whose value is greater of this and the passed variable. If in case these are equal, any of them may be returned.
Syntax of max() method of BigInteger class is as follows:
public BigInteger max(BigInteger val)
In our java example code we have created three BigInteger variables and we have then compared them with the use of max() method.
BigInteger maxResult = bigInteger1.max(bigInteger2);
Variable maxResult returns the BigInteger value of either of the bigIntger1 or of bigInteger2 which is maximum.Here is the full example code of the example code as follows:
import java.math.BigInteger;
|
Output of the example is as follows:
C:\biginteger>javac BigIntegerMaxValue.java C:\biginteger>java BigIntegerMaxValue Max big integer in123456789 and 112334 is ==>123456789 Max big integer in123456789 and 987654321 is ==>987654321 |