在 Java 中通过字符串创建 BigInteger
java 8object oriented programmingprogramming
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