在 Java 中求 BigInteger 的相反数
在 Java 中使用 BigInteger negate() 方法求 BigInteger 的相反数。
首先,让我们创建一个对象 -
BigInteger one, two; one = new BigInteger("200");
对上述进行求反并将其赋值给第二个对象 -
two = one.negate();
以下是一个示例 -
示例
import java.math.*; public class BigIntegerDemo { public static void main(String[] args) { BigInteger one, two; one = new BigInteger("200"); System.out.println("Actual Value: " +one); // negate two = one.negate(); System.out.println("Negated Value: " +two); } }
输出
Actual Value: 200 Negated Value: -200
Advertisement