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以来一直使用它。该计划是为了找到素数,并且已经工作了一段时间了。自从我决定尝试切换语句以来,我一直有问题。当我去运行代码时,Eclipse IDE会提示“类型不匹配:无法从布尔型转换为int型”,因此我的程序拒绝运行。我用我投入类型的地方评论了我的代码,并且无处投入“布尔”类型的“我”。如果您对发生此问题的原因有任何疑问,请告诉我。如果您需要任何其他信息,请不要问!谢谢!“布尔”和“开关”语句(错误)
你需要了解在一本书上的Java有一个例子,'之开关语句。这不是它应该使用的方式。 – dasblinkenlight