Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/372.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 - Fatal编程技术网

Java 将BigInteger拆分为数字并将它们放入数组中

Java 将BigInteger拆分为数字并将它们放入数组中,java,biginteger,Java,Biginteger,我想将下面的biginteger拆分为数字,并将其放入数组中 BigInteger = 123456789123456789123456789123456789 array[]={1,2,3,4,5,6,7,8,9,1,2,3,4,5,6,7,8,9,1,2,3,4,5,6,7,8,9,1,2,3,4,5,6,7,8,9,} 我该怎么做?谢谢。我搜索了它,但找不到更好的答案。只需执行toString,将每个字符转换为int,并添加到int的数组中即可 String biStr = bi.toS

我想将下面的biginteger拆分为数字,并将其放入数组中

BigInteger = 123456789123456789123456789123456789
array[]={1,2,3,4,5,6,7,8,9,1,2,3,4,5,6,7,8,9,1,2,3,4,5,6,7,8,9,1,2,3,4,5,6,7,8,9,}

我该怎么做?谢谢。我搜索了它,但找不到更好的答案。

只需执行
toString
,将每个字符转换为
int
,并添加到
int
的数组中即可

String biStr = bi.toString();
int[] ints = new int[biStr.length()];
for(int i=0; i<biStr.length(); i++) {
    ints[i] = Integer.parseInt(String.valueOf(biStr.charAt(i)))
}
String biStr=bi.toString();
int[]int=new int[biStr.length()];

对于(int i=0;i可以按如下方式进行:

BigInteger value = new BigInteger("123456789123456789123456789123456789");
List<Integer> list = new ArrayList<Integer>();
BigInteger ten = new BigInteger("10");
while (!value.equals(BigInteger.ZERO))
{
    list.add(0, value.mod(ten).intValue());
    value = value.divide(ten);
}
BigInteger值=新的BigInteger(“123456789123456789123456789123456789123456789”);
列表=新的ArrayList();
BigInteger十=新的BigInteger(“10”);
而(!value.equals(BigInteger.ZERO))
{
添加(0,value.mod(十).intValue());
值=值。除以(十);
}