The
java.math.BigInteger.subtract(BigInteger val) is used to calculate the Arithmetic difference of two BigIntegers. This method is applicable on large value numbers of range much greater than the range of biggest data type double of Java without compromising with the precision of the result but as BigInteger class internally uses array of integers for processing, the operation on object of BigIntegers are not as fast as on primitives. This method performs an operation upon the current BigInteger by which this method is called and BigInteger passed as the parameter.
Syntax:
public BigInteger subtract(BigInteger val)
Parameters: This method accepts a parameter
val which is the value to be subtracted from this BigInteger.
Return value: This method returns a BigInteger which holds difference (this - val).
Below programs is used to illustrate the subtract() method of BigInteger.
Example 1:
Output:
The difference of
56454210032311316797946498748
and
34664864678464621214565587864
is
21789345353846695583380910884
Example 2: