If no space is taken in a row or column or diagonal, then they will all be " "
. However, that will still satisfy a condition, such as
board[i][0].equals(board[i][1]) && board[i][1].equals(board[i][2])
Then it will return " "
right away and not check the other positions. " "
is the winner! But you also use " "
to indicate that there's no winner.
Add an additional check to your conditions to make sure that the first position you check is not equal to " "
before checking the rest of the conditional expression:
!" ".equals(board[i][0]) &&
board[i][0].equals(board[i][1]) &&
board[i][1].equals(board[i][2])
And you can change the other conditions similarly.