Java Tic Tac Toe console
Adding to Bobby's very good answer, you could also explore alternative ways for checking the winning game.
You can think of noughts and crosses as 1s and 0s (true and false):
boolean[][] board = new boolean[][]{
     {false, false, false},
     {false, true, false},
     {false, false, true}
};

and therefore transform the board to an integer number:
int intboard = 0;
int exponent = 0;
for (int i = 0; i &lt; board.length; i++) {
    for (int j = 0; j &lt; board[0].length; j++) {
        intboard += board[i][j] ? Math.pow(2, exponent) : 0;
        exponent++;
    }
}

Then you can simply check intboard against a set of pre-calculated integers for all winning boards:
List&lt;Integer&gt; winningBoards = List.of(
        7, // Horizontal, row-0 --&gt; 000000111
        56, // Horizontal, row-1 --&gt; 7 &lt;&lt; 3
        448, // Horizontal, row-2 --&gt; 7 &lt;&lt; 6
        73, // Vertical, column-0 --&gt; 001001001
        146, // Vertical, column-1 --&gt; 73 &lt;&lt; 1
        292, // Vertical, column-2 --&gt; 73 &lt;&lt; 2
        273, // Diagonal-0 --&gt; 100010001
        84 // Diagonal-1 --&gt; (273 &gt;&gt; 2) | 16
);


Note that you can calculate some of these winning boards using bitwise operations too!

Finally checking for the winning cases is a matter of applying the winningBoards masks on intboard:
final int boardToCheck = intboard;
boolean youHaveWon = winningBoards.stream()
        .anyMatch(winningboard -&gt; (boardToCheck &amp; winningboard) == winningboard);

System.out.println(&quot;Nought has won: &quot; + youHaveWon);

If you want to check for crosses you simply need to flip the bits of the winning boards using the complement operator ~:
youHaveWon = winningBoards.stream()
        .anyMatch(winningboard -&gt; (~boardToCheck &amp; winningboard) == winningboard);

System.out.println(&quot;Cross has won: &quot; + youHaveWon);

The advantage of this technique is not clear for a game as simple as noughts and crosses, but if you are working on more complex games and need to check many many boards (even millions or billions!) when performing Minimax or equivalent, you can get a very nice speed up by changing the representation of your game from using objects to bits.