import java.util.*; public class NQueens { public static boolean solve(Board solution) { return explore(solution, 1); } public static boolean explore(Board b, int col) { if (col == b.size() + 1) { return true; } for (int i = 1; i <= b.size(); i++) { if (b.safe(i, col)) { b.place(i, col); if (explore(b, col + 1)) { return true; } b.remove(i, col); } } return false; } public static void main(String[] args) { giveIntro(); Scanner console = new Scanner(System.in); System.out.print("What size board do you want to use? "); int size = console.nextInt(); System.out.println(); Board b = new BoardFrame(size); solve(b); } public static void giveIntro() { System.out.println("This program solves the classic '8 queens'"); System.out.println("problem, placing queens on a chessboard so"); System.out.println("that no two queens threaten each other."); System.out.println(); } }