this method must return a result of type boolean, java

前端 未结 5 1290
孤独总比滥情好
孤独总比滥情好 2020-11-28 16:04
 public boolean Winner() {
    for (int z = 0; z < 3; z++) {
            if (board[z] != null && board[z] == board[z+3] && board[z] == board[z+6]
         


        
5条回答
  •  南笙
    南笙 (楼主)
    2020-11-28 16:55

    The Java compiler doesn't make assumptions that a for loop will have an iteration or that an if statement block will run.

    There are execution paths where there is no return statement. What happens if the execution path doesn't execute any of the existing return statements and drops to the bottom? There isn't a return there.

    Add a return at the bottom.

提交回复
热议问题