我正在尝试使用一些更大的整数值,但我在初始化BigInteger变量时遇到了一些问题.我一直在做:
BigInteger x = new BigInteger("" + (Math.pow(2, n)));
Run Code Online (Sandbox Code Playgroud)
其中n是100s中的某个数字,但这会引发NumberFormatException.我不认为我可以使用BigInteger,Valueof(),因为这需要很长时间,我认为不够大.任何帮助,将不胜感激.
这种或那种方式Math.pow返回double将使用小数分隔符格式化的类型的值.BigInteger不能接受小数值.
抛出:
NumberFormatException- val不是a的有效表示BigInteger.
只需使用pow提供的方法BigInteger
BigInteger x = BigInteger.TWO.pow(n);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
81 次 |
| 最近记录: |