Java.math.BigInteger.not() Method


Advertisements


Description

The java.math.BigInteger.not() returns a BigInteger whose value is (~this). This method returns a negative value if and only if this BigInteger is non-negative.

Declaration

Following is the declaration for java.math.BigInteger.not() method.

public BigInteger not()

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.not() method.

package com.tutorialspoint;

import java.math.*;

public class BigIntegerDemo {

   public static void main(String[] args) {

      // create 4 BigInteger objects
      BigInteger bi1, bi2, bi3, bi4;

      // assign values to bi1, bi2
      bi1 = new BigInteger("6");
      bi2 = new BigInteger("-6");

      // perform not operation on bi1 and bi2
      bi3 = bi1.not();
      bi4 = bi2.not();

      String str1 = "Result of not operation on " + bi1 +" gives " +bi3;
      String str2 = "Result of not operation on " + bi2 +" gives " +bi4;

      // print bi3, bi4 values
      System.out.println( str1 );
      System.out.println( str2 );
   }
}

Let us compile and run the above program, this will produce the following result −

Result of not operation on 6 gives -7
Result of not operation on -6 gives 5

java_math_biginteger.htm

Advertisements