一个新用户在这里......我觉得我的代码是错误的。
我想寻求帮助,因为我对 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 < 9”的位置,尽管我不知道如何修复它。
欢迎任何更正/请求查看我的代码,非常感谢那些提供帮助的人!