透過字串在 Java 中建立 BigInteger
BigInteger 類用於超出基本資料型別限制的大整數計算。它提供模組算術、GCD 計算、質數測試、質數生成、位操作以及一些其他雜項運算。
首先,設定一個字串 −
String str = "268787878787687";
現在,建立一個新物件用於 BigInteger 並傳遞上面的字串 −
BigInteger bInteger = new BigInteger(str);
下面是一個示例 −
示例
import java.math.BigInteger;
public class Demo {
public static void main(String[] argv) throws Exception {
String str = "268787878787687";
BigInteger bInteger = new BigInteger(str);
System.out.println(bInteger);
}
}輸出
268787878787687
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP