这里有一个新用户......我觉得我的代码是错误的。我想寻求帮助,因为我对 Greenfoot 的计划比较陌生。手头的问题如问题中所述:我在编译我的代码时收到“不兼容的类型”错误,无论我做了什么修改,我似乎都无法修复它。问题所在的具体代码部分如下: public void answerValidation() { int ansCorrect = 0; int ansIncorrect = 0; for(int i = 0; i <= 10; i++) { answerArray[0] = array1[0] * array2[0]; if(answer != answerArray[0]) { ansIncorrect = ansIncorrect + 1; JOptionPane.showMessageDialog(null, array1[0] + "*" + array2[0] + "=" + answerArray[0]); } else { ansCorrect = ansCorrect + 1; } } switch(ansCorrect) { case 10: JOptionPane.showMessageDialog(null, "Wow! You got all the questions right!"); break; case ansCorrect>=8 && ansCorrect < 9: JOptionPane.showMessageDialog(null, "You scored" + ansCorrect + "out of 10. 80%-90% scored."); break; case ansCorrect >=6 && ansCorrect < 7: JOptionPane.showMessageDialog(null, "You scored" + ansCorrect + "out of 10. Keep practicing in Lv2 to improve."); break; case ansCorrect == 0 && ansCorrect < 6: JOptionPane.showMessageDialog(null, "You scored" + ansCorrect + "out of 10. Keep practicing in Lv1 to improve."); break; }}编译错误指出它位于“&& ansCorrect 欢迎任何更正/请求查看我的代码,非常感谢那些提供帮助的人! 最佳答案 case ansCorrect>=8 && ansCorrect < 9:switch case 中的 param 必须是解析为 boolean 的 int wnere case ansCorrect>=8 && ansCorrect < 9: 。如果你在 ansCorrect>=8 && ansCorrect < 9 看到逻辑那正是 case 8 ??和 case ansCorrect >=6 && ansCorrect < 7: 一样,应该写为 case 6 。关于 case ansCorrect == 0 && ansCorrect < 6 ,您可以编写多个具有相同功能的案例case 0;case 1;case 2;case 3;case 4;case 5;JOptionPane.showMessageDialog(null, "You scored" + ansCorrect + "out of 10. Keep practicing in Lv1 to improve.");break;关于java - Greenfoot/Java - 不兼容的类型 : boolean cannot be converted to int,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32518490/ 10-12 05:41