import java.math.BigInteger;
public class Classes{
static int i; //"i" is initialized
static int x = 200; //FYI, x is the upper limit for primes to be found (ex, in this case, 0 - 200)
public static void main(String[] args) {
for(i = 0; i < x;){ //"i" is assigned the value of 0
BigInteger one = BigInteger.valueOf(i); // The following lines find the prime(s)
one = one.nextProbablePrime(); // Order by which primes are found - int > BigInteger > int
i = one.intValue(); //'i" is re-assigned the a value
if(i >= x){
System.exit(i);
}
switch(i){
case i < 100: // ERROR HERE, "Type mismatch: cannot convert from boolean to int"
hex();
break;
case i > 100: // ERROR HERE, "Type mismatch: cannot convert from boolean to int"
baseTen();
break;
}
}
}
static void hex(){ //Probably unimportant to solving the problem, but this is used to convert to hex / print
String bla = Integer.toHexString(i);
System.out.println(bla);
}
static void baseTen(){ //Probably unimportant to solving the problem, but this is used print
System.out.println(i);
}
}
大家好,我希望你们一切都好。这是我第一次使用 Stack Overflow,所以对于我可能犯的任何错误,我提前道歉。所以,让我们开始吧!我在学习 Java 时编写了上面的代码作为练习片段,并且一直在使用它来练习和玩 Java。该程序用于查找素数,并且已经运行了一段时间。自从我决定尝试 switch 语句以来,我一直遇到问题。当我运行代码时,Eclipse IDE 显示“类型不匹配:无法从布尔值转换为 int”,因此我的程序拒绝运行。我已经用我转换类型的点注释了我的代码,并且我没有将“i”转换为“boolean”类型。如果您对为什么会出现此问题有任何想法,请告诉我。如果您需要任何其他信息,请务必询问!谢谢你!