Java.math.BigInteger.negate() 方法
描述
java.math.BigInteger.negate() 返回一个值为 (-this) 的 BigInteger。
声明
以下是 java.math.BigInteger.negate() 方法的声明。
public BigInteger negate()
参数
NA
返回值
此方法返回一个 BigInteger 对象,其值为 -this。
异常
NA
示例
下面的例子展示了 math.BigInteger.negate() 方法的使用。
package com.tutorialspoint;
import java.math.*;
public class BigIntegerDemo {
public static void main(String[] args) {
// create 2 BigInteger objects
BigInteger bi1, bi2;
bi1 = new BigInteger("20");
// assign negate value of bi1 to bi2
bi2 = bi1.negate();
String str = "Negated value of " + bi1 + " is " +bi2;
// print bi2 value
System.out.println( str );
}
}
让我们编译并运行上面的程序,这将产生下面的结果 −
Negated value of 20 is -20

