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