Java.math.BigInteger.not()方法範例


java.math.BigInteger.not() 返回一個BigInteger,其值是(~this)。此方法返回一個負值,當且僅當此BigInteger非負.

宣告

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

public BigInteger not()

引數

  • NA

返回值

該方法返回一個BigInteger物件的值是 ~this.

異常

  • NA

例子

下面的例子顯示math.BigInteger.not()方法的用法

package com.yiibai;

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