gpt4 book ai didi

java - 编译代码时出现错误的操作数错误

转载 作者:行者123 更新时间:2023-12-02 11:09:11 29 4
gpt4 key购买 nike

每次我尝试编译代码时,都会遇到“错误操作数”错误,该错误涉及 bool(boolean) 和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

最佳答案

您正在尝试添加带有整数的 bool(boolean) 值...。

直接打印并节省时间转换类型

System.out.print(" " + exam.questionsMissed()[i]+i+1);

关于java - 编译代码时出现错误的操作数错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36026776/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com