BigInteger divide() in Java

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

Syntax:

BigInteger java.math.BigInteger.divide(BigInteger val)

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

Parameters: One parameter is required for this method.

val: value by which this BigInteger is to be divided.

Returns: this / val.

Throws: ArithmeticException - if val is zero.

For Example:

BigInteger bigInteger = new BigInteger("1234")

BigInteger val = new BigInteger("7")

bigInteger.divide(val) = > It returns 176.

Approach

Java

import java.math.BigInteger;

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

        BigInteger bigInteger = new BigInteger("1234");
        BigInteger val = new BigInteger("7");
        System.out.println(bigInteger.divide(val));
    }
}

Output:

176

No comments:

Post a Comment