The max
method of the BigInteger
class returns the maximum of the current object and the passed argument.
In Java, the
BigInteger
class handles big integer mathematical operations that are outside the limits of all primitive types.
public BigInteger max(BigInteger val)
The max
method takes a BitInteger
object as a parameter.
If the parameter passed is greater than the current object value, then the parameter is returned. Otherwise, the current object is returned.
If the parameter and current object are equal, then either one of them is returned.
The example below demonstrates how to use the max
method.
import java.math.BigInteger;class BigIntegerMaxExample {public static void main( String args[] ) {BigInteger val1 = new BigInteger("99");BigInteger val2 = new BigInteger("100");BigInteger result = val1.max(val2);System.out.println(result);}}
In the code above,
BigInteger
class.import java.math.BigInteger;
BigInteger
objects: val1
with value 99
and val2
with value 100
.BigInteger val1 = new BigInteger("99");
BigInteger val2 = new BigInteger("100");
max
method on the val1
object with val2
as an argument. This returns the val2
object as result because val2 > val1
.BigInteger result = val1.max(val2); //val2 - 100