Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
Negate a BigInteger in Java
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 −
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);
}
}
Output
Actual Value: 200 Negated Value: -200
Advertisements
