I am working on an 8 queens problem, I am to place all 8 queens on the board before figuring out if they will attack one another. I am attempting to do this using a 2d array. How do I create random queens (1's) for each row, but making sure there is only 1 queen per column? This is what I have so far... which is just creating/printing the array of 0's.
public class EightQueens2 {
public static void main(String[] args) {
// create an 8x8 array for the chess board
final int CHESS_BOARD = 8;
int[][] board = new int[CHESS_BOARD][CHESS_BOARD];
//fill in the board with zeros, empty squares
for(int i = 0; i < board.length; i++){
for(int j = 0; j < board[i].length; j++){
System.out.print(board[i][j] + " ");
}
System.out.println();
}
}
}