通过字符串在 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