【发布时间】:2016-03-16 04:25:40
【问题描述】:
每次我尝试编译我的代码时,都会收到涉及布尔和 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
【问题讨论】:
-
问题在于尝试将布尔值添加到整数。您能告诉我
missedIndex = exam.questionsMissed()[i]+1;背后的想法吗? -
每次你尝试编译你的代码你都会得到这个编译错误。编译前不能运行。
标签: java arrays compiler-errors boolean