title: 8 Queens Algorithm: Not getting full result set
body: <p>Below is my attempt at printing all the solutions of the 8 queens problem (place 8 queens on a chessboard such that none of them are attacking each other). However, this solution is only printing 4 answers, whereas 92 should exist. Anyone see what's wrong? </p>
  
  <pre><code>static int[][] visited = new int[8][8];
  static int[][] board = new int[8][8];
  static int numQueens = 0;
  public static void main(String[] args) {
          //call recursive method from every starting position            
          for(int i=0; i&lt;8; i++){
              for(int j=0; j&lt;8; j++){
                  putQueens(board, i, j);
                  //clear board and visited array, as well as numQueens
                  for(int i2=0; i2&lt;8; i2++){
                      for(int j2=0; j2&lt;8; j2++){
                          board[i2][j2]=0;
                          visited[i2][j2]=0;
                      }
                  }
                  numQueens=0;
              }
          }
  }
  
  static void putQueens(int[][]board, int row, int col){
  
          if(visited[row][col]==1)
              return;
          visited[row][col]=1;
          boolean hasQueen = false;
              //check columns
          for(int j=0; j&lt;board[0].length; j++){
              if(board[row][j]==1)
                  hasQueen = true;
          }
              //check rows
          for(int i=0; i&lt;board.length; i++){
              if(board[i][col]==1)
                  hasQueen = true;
  
          }
              //check diagonals
          for(int i=row; i&lt;board.length; i++){
              if(col+(i-row)&lt;=7){
  
                  if(board[i][col+(i-row)]==1)
                      hasQueen=true;
              }
  
          }    
              //check diagonals
  
          for(int i=row; i&gt;=0; i--){
              if(col-(row-i)&gt;=0){
                  if(board[i][col-(row-i)]==1)
                      hasQueen=true;
              }
          }                    
              //check diagonals
          for(int i=row; i&lt;board.length; i++){
              if(col-(i-row)&gt;=0){    
                  if(board[i][col-(i-row)]==1)
                      hasQueen=true;
              }
  
          }
              //check diagonals
  
          for(int i=row; i&gt;=0; i--){
              if(col+(row-i)&lt;=7){
                  if(board[i][col+(row-i)]==1)
                      hasQueen=true;
              }
          }
              //print if solution
          if(!hasQueen){
              board[row][col] = 1;
              numQueens++;
  
              if(numQueens==8){
                  System.out.println("==========");
                  for(int i=0; i&lt;8; i++){
                      for(int j=0; j&lt;8; j++){
                          System.out.print(String.format("%3s", board[i][j]));
                          board[i][j]=0;
                      }
                      System.out.println("");
  
                  }
                  numQueens=0;
  
  
              }
  
          }
  
          //recurse
          if(row!=7)
              putQueens(board, row+1, col);
          if(col!=7)  
              putQueens(board, row, col+1);
          if(row!=0)
              putQueens(board, row-1, col);
          if(col!=0)
              putQueens(board, row, col-1);
  
  
      }
  </code></pre>