public class EightRooks { static int [] rowNumbers = new int[8]; // ith entry in state, from 0 to howManyPlaced-1, indicates the row number of the rook in column i static int curColumn = 0; static boolean [] isOccupied = new boolean[8]; // is true if row i is occupied private static int howManyWays() { System.out.println(curColumn); if (curColumn==8) return 1; int total = 0; for (int row=0; row<8; row++) { if (!isOccupied[row]) { rowNumbers[curColumn]=row; isOccupied[row]=true; curColumn++; total+=howManyWays(); isOccupied[row]=false; curColumn--; } } return total; } /** * @param args */ public static void main(String[] args) { System.out.println(howManyWays()); } }