title: Tic-Tac-Toe game results in draw every time
body: <p>I'd like to think the code is pretty clear. I am a beginner programmer and every thing looks fine to me. What should you do in situations like these when everything looks perfect but the program doesn't run as planned?</p>
  <p>In short, I'm asking to advice for outlook on coding projects &amp; a solution as to why my method I spent over 45 minutes on does nothing.</p>
  <pre><code>import java.util.Scanner;
  
  public class TicTacToe {
  
      public static boolean elementsAreAllEqual(char[] arr) {
  
          for(int i = 0; i &lt; arr.length; i++) {
              if(arr[i] != arr[i + 1]) {
                  return false;
              }
          }
          return true;
      }
  
      public static boolean some1HasWon(char[][] g) {
  
          char[] treE = new char[3];
  
          // horizontal straight lines (rows of 3 alike)
          for(int r = 0; r &lt; g.length; r++) {
              for(int c = 0; c &lt; g.length; c++) {
                  treE[c] = g[r][c];
              }
              if(elementsAreAllEqual(treE)) {
                              return true;
                      }
              treE = new char[3];
          }
  
          // vertical straight lines (columns of 3 alike)
          for(int c = 0; c &lt; g.length; c++) {
                          for(int r = 0; r &lt; g.length; r++) {
                                  treE[r] = g[c][r];
                          }
                          if(elementsAreAllEqual(treE)) {
                              return true;
                      }
                          treE = new char[3];
                  }
  
          // upward diagonal
          for(int i = 0; i &lt; g.length; i++) {
              treE[i] = g[g.length-i-1][i];
          }
          if(elementsAreAllEqual(treE)) {
              return true;
          }
          treE = new char[3];
  
          // downward diagonal
          for(int i = 0; i &lt; g.length; i++) {
              treE[i] = g[i][i];
          }
          if(elementsAreAllEqual(treE)) {
                          return true;
                  }
  
          return false;
      }
  
      public static void main(String args[]) {
  
          char[][] grid = new char[3][3];
          Scanner s = new Scanner(System.in);
          System.out.println(&quot;Tic-Tac-Toe\n&quot;);
  
          int goCount = 0;
          char player;
          boolean draw = true;
          boolean end = false;
  
          do {
              if(goCount % 2 == 0) {
                  player = 'X';
                  System.out.print(&quot;'&quot; + player + &quot;', choose your location (row, column): &quot;);
              }
              else {
                  player = 'O';
                  System.out.print(&quot;'&quot; + player + &quot;', choose your location (row, column): &quot;);
              }
              String position = s.nextLine();
              String[] p = position.split(&quot; &quot;);
              int[] pos = {Integer.parseInt(p[0]), Integer.parseInt(p[1])}; 
  
              grid[pos[0]][pos[1]] = player;
  
              System.out.println();
  
              for(int y = 0; y &lt; 3; y++) {
                  System.out.print(&quot;\t&quot;);
                  for(int x = 0; x &lt; 3; x++) {
                      if(grid[y][x] != ' ') {
                          System.out.print(grid[y][x] + &quot; &quot;);
                      }
                      else {
                          System.out.print(&quot;  &quot;);
                      }
                  }
                  System.out.println();
              }
  
              System.out.println();
  
              if(goCount &gt; 4) {
                  if(some1HasWon(grid)) {
                      end = true;
                  }
                  else if(goCount &gt;= 8) {
                      draw = true;
                      end = true;
                  }
              }
              goCount++;
          }
          while(end != true);
  
          if(draw) {
              System.out.println(&quot;The game was a draw.&quot;);
          }
          else if(goCount % 2 == 0) {
              System.out.println(&quot;Player 'X' wins the game.&quot;);
          }
          else {
              System.out.println(&quot;Player 'O' wins the game.&quot;);
          }
      }
  
  }
  
  </code></pre>