this method must return a result of type boolean, java

Right now, the function isn’t guaranteed to return a boolean, because it’s possible that neither of the if statements will ever be entered.

You could fix it like this (but only do this if it’s actually what your logic needs!):

public boolean Winner() {
    for (int z = 0; z < 3; z++) {
            if (board[z] != null && board[z] == board[z+3] && board[z] == board[z+6]
                    ) {
                return true;
            } 
    }
    for(int i=0; i<7;i+=3){
        if (board[i] != null && board[i] == board[i+1] && board[i] == board[i+2]) {

    return true;}
    }

    return false;
}

Leave a Comment