BigInteger negate()

优质
小牛编辑
121浏览
2023-12-01

描述 (Description)

java.math.BigInteger.negate()返回一个BigInteger,其值为(-this)。

声明 (Declaration)

以下是java.math.BigInteger.negate()方法的声明。

public BigInteger negate()

参数 (Parameters)

NA

返回值 (Return Value)

此方法返回一个BigInteger对象,其值为-this。

异常 (Exception)

NA

例子 (Example)

以下示例显示了math.BigInteger.negate()方法的用法。

package cn.xnip;
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