BigInteger not()

优质
小牛编辑
133浏览
2023-12-01

描述 (Description)

java.math.BigInteger.not()返回一个BigInteger,其值为(〜this)。 当且仅当此BigInteger为非负数时,此方法返回负值。

声明 (Declaration)

以下是java.math.BigInteger.not()方法的声明。

public BigInteger not()

参数 (Parameters)

NA

返回值 (Return Value)

此方法返回一个BigInteger对象,其值为〜this。

异常 (Exception)

NA

例子 (Example)

以下示例显示了math.BigInteger.not()方法的用法。

package cn.xnip;
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 );
   }
}

让我们编译并运行上面的程序,这将产生以下结果 -

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