The remainder
method of the BigInteger
class can be used to get the remainder of the division of the current BigInteger
object by the passed BigInteger
.
In other words, the function performs the modulo operation (%
) for very big integers.
In Java, the
BigInteger
class handles very big integer mathematical operations that are outside the limits of all primitive types.
public BigInteger remainder(BigInteger val)
This method takes a BigInteger
object as an argument. remainder
throws ArithmeticException
if the value of the argument is 0
.
The remainder
method returns a BigInteger
object. The value of the returned BigInteger
object is the remainder
of the division of the current BigInteger
value by the passed argument value.
The example below demonstrates how to use the remainder
method.
import java.math.BigInteger;class BigIntegerRemainderExample {public static void main( String args[] ) {BigInteger val1 = new BigInteger("33297360");BigInteger val2 = new BigInteger("676543");BigInteger result = val1.remainder(val2);System.out.println(result);}}
In the above code:
BigInteger
class.import java.math.BigInteger;
BigInteger
objects, val1
with value 33297360
and val2
with value 676543
.BigInteger val1 = new BigInteger("33297360");
BigInteger val2 = new BigInteger("676543");
remainder
method on the val1
object with val2
as an argument. This method call will return a BigInteger
that has a value equal to the remainder of val1 / val2
(i.e. 33297360 % 676543 = 146753).BigInteger result = val1.remainder(val2); //146753