title: Getting a stack overflow from this recursive method?
body: <p>Here is the method, it ideally should solve the eight-queens problem by placing Qs on the board so that none of them threaten each other, but I can't seem to stop it from infinitely recursing.</p>
  
  <pre><code>public static void solve(int row, int col, int size, char[][] array) {
      for (int i = 0; i &lt; size - 2; i++) {
          if (isSafe(row, col, size, array)) {
              array[i][col] = 'Q';
          } else {
              if (col &lt; size - 2) {
                  solve(row, col++, size, array); //changed ++ to +1
              }
          }
      }
  }
  </code></pre>
  
  <p>For clarity, here is the included 'isSafe' method:</p>
  
  <pre><code>public static boolean isSafe(int row, int col, int size, char[][] array) {
      //check column
      for (int i = 0; i &lt; size - 1; i++) {
          if (array[i][col] == 'Q') {
              return false;
          }
      }
      //horizontal
      for (int i = size - 1; i &gt;= 0; i--) {
          if (array[row][i] == 'Q') {
              return false;
          }
      }
      //up diagonal
      while (row &gt; 0 &amp;&amp; col &gt; 0) {
          int x = row;
          int y = col;
          if (array[row - 1][col - 1] == 'Q') {
              return false;
          } else {
              x--;
              y--;
          }
      }
      //down diagonal
      while (row &lt; size - 1 &amp;&amp; col &gt; 0) {
          int x = row;
          int y = col;
          if (array[row + 1][col - 1] == 'Q') {
              return false;
          } else {
              x++;
              y--;
          }
      }
      return true;
  }
  </code></pre>
  
  <p>Thank you for any light you can shed on this.<br>
  EDIT : So I just figured out that by changing '++' to '+1' I was able to stop the stack overflow, but my method does not recurse like I want it to so a question still remains</p>