在 Java 中從一個 BigInteger 中減去另一個 BigInteger
使用 Java 中的 BigInteger subtract() 方法從另一個 BigInteger 中減去一個 BigInteger。
首先,讓我們建立一些物件 -
BigInteger one, two, three;
one = new BigInteger("200");
two = new BigInteger("150");減去上面的內容並將其分配給第三個物件 -
three = one.subtract(two);
以下是一個示例 -
示例
import java.math.*;
public class BigIntegerDemo {
public static void main(String[] args) {
BigInteger one, two, three;
one = new BigInteger("200");
two = new BigInteger("150");
three = one.subtract(two);
String res = one + " - " + two + " = " +three;
System.out.println("Subtraction: " +res);
}
}輸出
Subtraction: 200 - 150 = 50
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP