简体   繁体   English

为什么我会收到意外的类型、需要变量的错误? 即使我使用的是变量

[英]Why am I getting a unexpected type, variable required error? even though I am using a variable

List <BigInteger> valaArr = new ArrayList <BigInteger>();
        Scanner value = new Scanner(System.in);
        System.out.print("Enter number to test for prime: ");
        BigInteger n = value.nextBigInteger();

        for(BigInteger i = BigInteger.valueOf(1); i.compareTo(n) = -1; i = i.add(BigInteger.valueOf(1)))
        {
            valaArr.add(i);
        }

Apparently my i.compareTo(n) is giving me a unexpected type, variable required value found.显然我的 i.compareTo(n) 给了我一个意想不到的类型,找到了变量所需的值。 Any idea why is it happening even though my i and n are variables?知道为什么会发生,即使我的 i 和 n 是变量?

You can try this solution你可以试试这个解决方案

for(BigInteger i = BigInteger.valueOf(1); i.compareTo(n) <0; i = i.add(BigInteger.valueOf(1)))
{
 valaArr.add(i);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么我收到错误:需要意外类型:找到变量:值 - Why am I getting the Error: unexpected type required: variable found: value 为什么我收到变量未初始化错误? - Why am I getting variable not initialized error? 为什么我收到错误作为意外令牌 - why I am getting error as unexpected token Java:设置字符串中字符位置的值时,我收到意外的类型错误(必填:变量;找到:值) - Java: I am receiving an unexpected type error(required: variable; found: value) when setting the value of a character location in a string 为什么即使使用锁,也会出现ConcurrentModificationException? - Why I get ConcurrentModificationException even though I am using locks? 为什么我的JFrame出现变量声明错误? - Why am I getting Variable Declaration error with JFrame? 为什么我收到错误 this.variable is null in java class - Why I am getting error this.variable is null in java class 为什么通过在泛型中将Integer类型参数设置为Integer变量而出错? - Why i am getting error by setting the Integer type parameter to the Integer variable in generics? 为什么会出现类型不匹配错误? - Why am I getting Type mismatch error? 为什么我会收到不可转换的类型错误? - Why am I getting an inconvertible type error?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM