Java subtract BigInteger
Tags: BigInteger BigInteger subtract
In this Java core tutorial we learn how to use the java.math.BigInteger.subtract() method to subtract two BigInteger values.
How to subtract two BigInteger values
To subtract BigInteger value we can use the java.math.BigInteger.subtract() method which returns the subtraction result of a BigInteger object and given argument BigInteger object.
SubtractBigIntegerExample.java
import java.math.BigInteger;
public class SubtractBigIntegerExample {
public static void main(String... args) {
BigInteger value1 = new BigInteger("987654321");
BigInteger value2 = new BigInteger("123456789");
BigInteger result = value1.subtract(value2);
System.out.println(value1 + " - " + value2 + " = " + result);
}
}
987654321 - 123456789 = 864197532
Happy Coding 😊