Use the BigInteger negate() method in Java to negate a BigInteger.
First, let us create an object −
BigInteger one, two; one = new BigInteger("200");
Negate the above and assign it to the second object −
two = one.negate();
The following is an example −
import java.math.*; public class BigIntegerDemo { public static void main(String[] args) { BigInteger one, two; one = new BigInteger("200"); System.out.println("Actual Value: " +one); // negate two = one.negate(); System.out.println("Negated Value: " +two); } }
Actual Value: 200 Negated Value: -200