Java 不兼容的类型:无法将BigInteger转换为int

Java 不兼容的类型:无法将BigInteger转换为int,java,arrays,biginteger,Java,Arrays,Biginteger,我试图运行此代码,但我得到的错误,我无法解决。请帮忙 import java.util.Scanner; import java.math.BigInteger; class Cseq { public static void main(String []args) { Scanner jais=new Scanner(System.in); int x=100000; BigInteger i; BigIntege

我试图运行此代码,但我得到的错误,我无法解决。请帮忙

import java.util.Scanner;
import java.math.BigInteger;
class Cseq
{
    public static void main(String []args)
    {
        Scanner jais=new Scanner(System.in);
        int x=100000;
        BigInteger i;
        BigInteger []a = new BigInteger[x];
        a[0]=BigInteger.ONE;
        for(i=BigInteger.ONE;i.compareTo(BigInteger.valueOf(x))<=0;i=i.add(BigInteger.ONE))
        {
            a[i]=a[(i.subtract(BigInteger.ONE))].multiply(i);
        }
        int t=jais.nextInt();
        while(t--!=0)
        {
        BigInteger n=jais.nextBigInteger();
        BigInteger p=jais.nextBigInteger();
        BigInteger q=jais.nextBigInteger();
        BigInteger v=(q.subtract(p)).add(BigInteger.ONE);
        BigInteger j;
        BigInteger sum=BigInteger.ZERO;
        for(j=BigInteger.ONE;j.compareTo(n)<=0;j=j.add(BigInteger.ONE))
        {
            sum=sum.add(a[v].divide(a[(v.subtract(j))].multiply(a[j])));
            sum=sum.add(v);
        }
        sum=sum.subtract(v);
        System.out.println(sum);
        }
        jais.close();
    }
}

您将得到5个错误,它们都与数组的索引值有关。应该是整数

在所有这些表达式中,您需要将表达式结果更改为整数值

a[i]=a[(i.subtract(BigInteger.ONE))].multiply(i);
这里i和i.subtractBigInteger.1应该是整数

这里v,v.j和j应该是整数

相应地更改这些索引数据类型。 在所有这些地方使用intValue

更改这行代码

a[i]=a[(i.subtract(BigInteger.ONE))].multiply(i);


这是指向这个问题的链接。。为什么我不能将数组的索引作为BigInteger?可以从BigInteger到Integer进行类型转换吗?@ASHISHJAISWAL您可以使用intValue;方法
a[i]=a[(i.subtract(BigInteger.ONE))].multiply(i);
a[i.intValue()]=a[(i.subtract(BigInteger.ONE)).intValue()].multiply(i);