- Java.math 包附加内容
- Java.math - 枚举
- Java.math - 讨论
Java.math.BigInteger.negate() 方法
说明
java.math.BigInteger.negate() 返回一个 BigInteger,其值为 -this。
声明
下面是 java.math.BigInteger.negate() 方法的声明。
public BigInteger negate()
参数
无
返回值
该方法返回一个 BigInteger 对象,其值为 -this。
异常
无
示例
以下示例展示了 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
java_math_biginteger.htm
广告