Java Data Type How to - Negate/Multiply/Subtract/Divide one BigInteger to another BigInteger








Question

We would like to know how to negate/Multiply/Subtract/Divide one BigInteger to another BigInteger.

Answer

//  w  w  w. j  av a2  s .c  o m
import java.math.BigInteger;

public class Main {
  public static void main(String[] argv) throws Exception {
    BigInteger bi1 = new BigInteger("1234567890123456890");
    BigInteger bi2 = BigInteger.valueOf(123L);

    bi1 = bi1.multiply(bi2);

    bi1 = bi1.subtract(bi2);

    bi1 = bi1.divide(bi2);

    bi1 = bi1.negate();

  }
}