先決條件:BigInteger基礎
的java.math.BigInteger.negate()方法返回一個BigInteger,其值為(-this)。 negate()方法將更改BigInteger的單個位。
用法:
public BigInteger negate()
參數:該方法不接受任何參數。
返回值:該方法返回(-this)的操作。
例子:
Input: value = 2300 Output: -2300 Explanation: Binary signed 2's complement of 2300 = 0000100011111100 Singed bit are 0000 change sing bit to 1111 so negate of 0000100011111100 in signed 2's complement is 1111011100000100 Decimal value = -2300. Input: value = 567689 Output: -567689
以下示例程序旨在說明BigInteger的negate()方法。
/*
*Program Demonstrate negate() method of BigInteger
*/
import java.math.*;
public class GFG {
public static void main(String[] args)
{
// Create BigInteger object
BigInteger biginteger = new BigInteger("2300");
// Call negate() method to find -this
BigInteger finalvalue = biginteger.negate();
String result = "Result of negate operation on " +
biginteger + " is " + finalvalue;
// Prints result
System.out.println(result);
}
}
輸出:
Result of negate operation on 2300 is -2300
參考: https://docs.oracle.com/javase/7/docs/api/java/math/BigInteger.html#negate()
相關用法
- Java BigInteger pow()用法及代碼示例
- Java BigInteger or()用法及代碼示例
- Java BigInteger mod()用法及代碼示例
- Java BigInteger xor()用法及代碼示例
- Java BigInteger abs()用法及代碼示例
- Java BigInteger not()用法及代碼示例
- Java BigInteger and()用法及代碼示例
- Java BigDecimal negate()用法及代碼示例
- Java BigInteger andNot()用法及代碼示例
- Java BigInteger clearBit()用法及代碼示例
- Java BigInteger modPow()用法及代碼示例
- Java BigInteger toString()用法及代碼示例
- Java BigInteger shiftLeft()用法及代碼示例
- Java BigInteger setBit()用法及代碼示例
- Java BigInteger shiftRight()用法及代碼示例
注:本文由純淨天空篩選整理自AmanSingh2210大神的英文原創作品 BigInteger negate() Method in Java。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。