I've implemented a Tic Tac Toe game with a public method checkWin() to check if the game has a winner. This is my code.public class TicTacToe {    int size;    int [][] board;    public TicTacToe(int size){        this.size = size;        board = new int[size][size];        for (int i = 0; i <size ; i++) {            for (int j = 0; j <size ; j++) {                board[i][j] = -1;            }        }    }    public void markCross(int row, int col){        if(row >= size || col >= size) {            throw new IllegalStateException(Invalid grid point);        }        board[row][col] = 1;    }    public void markZero(int row, int col){        if(row >= size || col >= size){            throw new IllegalStateException(Invalid grid location);        }        board[row][col] = 0;    }    public boolean checkWin(){       int countOnes = 0;        int countZeros = 0;        for (int i = 0; i < size; i++) {            for (int j = 0; j < size; j++) {                if(board[i][j] == 0) countZeros++;                else if(board[i][j] == 1)countOnes++;            }            if(countZeros == size || countOnes == size) return true;            break;        }        countOnes = 0;        countZeros = 0;        //check diagonal right        for (int i = 0, j= 0; i <size ; i++, j++) {            if (board[i][j] == 0) countZeros++;            else if(board[i][j] == 1) countOnes++;        }        if(countOnes == size || countZeros == size) return true;        //check diagonal left        for (int i = size-1, j= size-1; i >= 0 ; i--, j--) {            if (board[i][j] == 0) countZeros++;            else if(board[i][j] == 1) countOnes++;        }        if(countOnes == size || countZeros == size) return true;        return false;    }}
Check if a game of Tic-Tac-Toe has a winner
java;tic tac toe