在 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