Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/388.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在java中如何处理大于BigInteger的大数?_Java_Biginteger_Largenumber - Fatal编程技术网

在java中如何处理大于BigInteger的大数?

在java中如何处理大于BigInteger的大数?,java,biginteger,largenumber,Java,Biginteger,Largenumber,输入: BigInteger l = BigInteger.valueOf(111111111111111110); 编译器错误消息 整数太大 我的目标是不断减少给定的大数,直到某个值(比如K) 我怎样才能做到这一点 整数太大 它给出错误的原因是因为传入(…)的valueOf的参数的类型是一个有限制的int(除非您另外指定,否则这是默认类型),并且您已超过此限制,因此出现错误 BigInteger l = BigInteger.valueOf(111111111111111110); // a

输入:

BigInteger l = BigInteger.valueOf(111111111111111110);
编译器错误消息

整数太大

我的目标是不断减少给定的大数,直到某个值(比如K)

我怎样才能做到这一点

整数太大

它给出错误的原因是因为传入(…)的
valueOf的参数的类型是一个有限制的
int
(除非您另外指定,否则这是默认类型),并且您已超过此限制,因此出现错误

BigInteger l = BigInteger.valueOf(111111111111111110); // argument is int, so it will give a compiler error
改用
参数

BigInteger value = BigInteger.valueOf(111111111111111110L);
或者使用
字符串
参数

BigInteger value = new BigInteger("111111111111111110");

如何将输入转换为BigInteger?什么是“大于BigInteger”?如何在java中处理大于BigInteger的大数字?BigInteger的唯一限制是RAM。因此,您的数字不可能大于BigInteger所能容纳的数值。BigInteger l=BigInteger.valueOf(11111111111111 0);通过这种方式,将其转换为biginteger。
11111111111 0
大于max
int
值。将其作为字符串传递
new biginger(“11111111111 0”)
请使用
L
表示
long
后缀
L
L
更容易阅读,后者可以用一些字体解释为
1
。@Pshemo-sure.:)