- Java.math package classes
- Java.math - Home
- Java.math - BigDecimal
- Java.math - BigInteger
- Java.math - MathContext
- Java.math package extras
- Java.math - Enumerations
- Java.math - Discussion
Java.math.BigInteger.negate() Method
Description
The java.math.BigInteger.negate() returns a BigInteger whose value is (-this).
Declaration
Following is the declaration for java.math.BigInteger.negate() method.
public BigInteger negate()
Parameters
NA
Return Value
This method returns a BigInteger object whose value is -this.
Exception
NA
Example
The following example shows the usage of math.BigInteger.negate() method.
package com.tutorialspoint; import java.math.*; public class BigIntegerDemo { public static void main(String[] args) { // create 2 BigInteger objects BigInteger bi1, bi2; bi1 = new BigInteger("20"); // assign negate value of bi1 to bi2 bi2 = bi1.negate(); String str = "Negated value of " + bi1 + " is " +bi2; // print bi2 value System.out.println( str ); } }
Let us compile and run the above program, this will produce the following result −
Negated value of 20 is -20
java_math_biginteger.htm
Advertisements