Java BigInteger negate()方法
java.math.BigInteger.negate() 方法返回一个BigInteger,其值为(- this)。 negate()方法将改变BigInteger的单数位。
语法
public BigInteger negate()
参数: 该方法不接受任何参数。
返回值: 该方法返回(-this)的操作。
例子
输入: value = 2300
输出: -2300
解释:
2300的二进制符号2的补码=0000100011111100
有符号的位是0000
改变单数位为1111
所以0000100011111100的负数在有符号的2的补码中是111011100000100
十进制值=-2300。
输入: value = 567689
输出: -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()