Subtract one BigInteger from another BigInteger in Java


Use the BigInteger subtract() method in Java to Subtract one BigInteger from another.

First, let us create some objects −

BigInteger one, two, three;
one = new BigInteger("200");
two = new BigInteger("150");

Subtract the above and assign it to the third object −

three = one.subtract(two);

The following is an example −

Example

 Live Demo

import java.math.*;
public class BigIntegerDemo {
   public static void main(String[] args) {
      BigInteger one, two, three;
      one = new BigInteger("200");
      two = new BigInteger("150");
      three = one.subtract(two);
      String res = one + " - " + two + " = " +three;
      System.out.println("Subtraction: " +res);
   }
}

Output

Subtraction: 200 - 150 = 50

karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know

Updated on: 29-Jun-2020

89 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements