BigInteger mod() in Java

mod(): This method is available in java.math.BigInteger class of Java.

Syntax:

BigInteger java.math.BigInteger.mod(BigInteger m)

This method takes one argument of type BigInteger as its parameter. This method returns a BigInteger whose value is (this mod m).

Parameters: One parameter is required for this method.

m: the modulus.

Returns: this mod m.

Throws: ArithmeticException - m ≤ 0.

For Example:

BigInteger bigInteger = new BigInteger("1234")

BigInteger m = new BigInteger("7")

bigInteger.mod(m) = > It returns 2.

Approach

Java

import java.math.BigInteger;

public class BigIntegermod {
    public static void main(String[] args) {

        BigInteger bigInteger = new BigInteger("1234");

        BigInteger m = new BigInteger("7");
        System.out.println(bigInteger.mod(m));
    }
}

Output:

2

No comments:

Post a Comment