每当我尝试编译代码时,我都会得到一个糟糕的操作数'涉及布尔和int数组的错误。任何帮助,将不胜感激。谢谢!
System.out.println("Passed: " + passed);
if (exam.totalIncorrect() > 0)
{
System.out.println("The incorrect answers are: ");
int missedIndex;
for (int i = 0; i < exam.totalIncorrect(); i++)
{
missedIndex = exam.questionsMissed()[i]+1;
System.out.print(" " + missedIndex);
}
}
我得到的错误是:
DriverExamApplication.java:58: error: bad operand types for binary operator
'+'
missedIndex = exam.questionsMissed() [i] +1;
^
first type: boolean
second type: int
答案 0 :(得分:1)
您正在尝试添加一个带整数的布尔值....
直接打印并节省转换类型的时间
System.out.print(" " + exam.questionsMissed()[i]+i+1);
答案 1 :(得分:0)
看起来exam.questionsMissed()
返回一个布尔数组。然后exam.questionsMissed()[i]
是布尔值,你正在尝试向它追加1。