Java.math.BigInteger.not() 方法



描述

**java.math.BigInteger.not()** 返回值 (~this) 為 BigInteger。僅當此 BigInteger 非負時,此方法才會返回負值。

宣告

以下是 **java.math.BigInteger.not()** 方法的宣告。

public BigInteger not()

BigInteger not()

NA

返回值

此方法返回一個 BigInteger 物件,其值為 ~this。

異常

NA

示例

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 );
   }
}

即時演示

Result of not operation on 6 gives -7
Result of not operation on -6 gives 5
讓我們編譯並執行上述程式,它將產生以下結果 −
列印頁面
© . All rights reserved.