required:boolean found:int 1 error

时间:2017-10-27 02:12:11

标签: java

我不明白为什么我收到错误:

GuessingGame.java:15: error: incompatible types

我的代码:

for (numberOfTries=0; numberOfTries = 4; numberOfTries++){
}

required: boolean

found: int

1 error

当numberOfTries类型为int时,则为4

1 个答案:

答案 0 :(得分:0)

你有没有初始化numberOfTries

尝试更改此内容:

 for (numberOfTries=0; numberOfTries = 4; numberOfTries++){

要:

 for (int numberOfTries=0; numberOfTries <= 4; numberOfTries++){