在 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
数据结构
网络
关系型数据库管理系统 (RDBMS)
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
JavaScript
PHP