如何将任何数字添加到 BigInteger
中?我在 eclipse 中收到此错误:-
BigInteger 类型的 add(long) 方法不可见
import java.math.BigInteger;
public class M {
public static void main(String[] args) {
BigInteger a = new BigInteger("20000423242342342354857948787922222222222388888888888888888");
System.out.println("" + (a.add(2));
}
}
最佳答案
您无法将普通整数添加到 BigInteger
。
但是您可以将一个 BigInteger
添加到另一个 BigInteger
。因此,您应该将原始整数转换为 BigInteger,如下所示:
System.out.println(b.add(BigInteger.valueOf(2)));
关于java - BigInteger 类型的方法 add(long) 不可见,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46592321/