title: TicTacToe Java - check for winner
body: <p>Here is my code. I am trying to check for the winner. I am only a beginner, so please make it easy. I wanted the board to change sizes. So, I want the check for winner can get use to the size, it will not just check the 9 blocks.</p>
  
  <pre><code>import java.util.*;
  
  public class TicTacToe {
  
      private String[][] board;
      private Scanner console;
  
      public TicTacToe(String[][] table, Scanner console) {
          this.board = table;
          this.console = console;
      }
  
      public void makeTable() {
          for (int i = 0; i &lt; board.length; i++) {
              for (int j = 0; j &lt; board[i].length; j++) {
                  board[i][j] = "_";
              }
          }
      }
  
      public void printTable() {
          System.out.print(" ");
          for (int i = 0; i &lt; board.length; i++) {
              System.out.print(" " + i);
          }
          System.out.println();
          for (int i = 0; i &lt; board.length; i++) {
              System.out.print(i + "│");
              for (int j = 0; j &lt; board[i].length; j++) {
                  System.out.print(board[i][j] + "│");
              }
              System.out.println();
          }
      }
  
      public void play(Scanner console) {
          int turn = 0;
          String player = "_";
          makeTable();
          printTable();
          while (turn != 9) {
              int x = console.nextInt();
              int y = console.nextInt();
  
              while (x &gt;= board.length || y &gt;= board[1].length) {
                  System.out.println("Out of bounce, try again!!!");
                  x = console.nextInt();
                  y = console.nextInt();
              }
  
              while (board[y][x] != "_") {
                  System.out.println("Occupied, try again!!!");
                  x = console.nextInt();
                  y = console.nextInt();
              }
  
              if (turn % 2 == 0) {
                  player = "X";
              } else {
                  player = "O";
              }
              board[y][x] = player;
              turn++;
              printTable();
          }
      }
  
      public static void main(String[] args) {
          Scanner console = new Scanner(System.in);
          String[][] board = new String[3][3];
          TicTacToe ttt = new TicTacToe(board, console);
          ttt.play(console);
      }
  }
  </code></pre>