BigInteger negate() in Java

negate(): This method is available in java.math.BigInteger class of Java.

Syntax:

BigInteger java.math.BigInteger.negate()

This method returns a BigInteger whose value is (-this).

Note:

1. If the number is less than zero then negate it (i.e positive number is returned).

2. If the number is greater than zero then negate it (i.e negative number if returns).

3. If the number is zero then the same zero is returned.

Returns: -this

For Example:

BigInteger bigInteger = new BigInteger("1234")

bigInteger.negate() = > It returns -1234.

Approach

Java

import java.math.BigInteger;

public class BigIntegernegate {
    public static void main(String[] args) {

        BigInteger bigInteger = new BigInteger("1234");
        System.out.println(bigInteger.negate());
    }
}

Output:

-1234

No comments:

Post a Comment