BigInteger subtract() in Java

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

Syntax:

BigInteger java.math.BigInteger.subtract(BigInteger val)

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

Parameters: val value to be subtracted from this BigInteger.

Returns: this - val

For Example:

BigInteger bigInteger = new BigInteger("1234")

BigInteger val = new BigInteger("345")

bigInteger.subtract(val) = > It returns 889.

Approach

Java

import java.math.BigInteger;

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

        BigInteger bigInteger = new BigInteger("1234");

        BigInteger val = new BigInteger("345");
        System.out.println(bigInteger.subtract(val));
    }
}

Output:

889

No comments:

Post a Comment