I am working on a question and want to generate a specific pattern which is
1000
1100
1110
1111
0100
0110
0111
0010
0011
0001
using recursion and a for loop but when I write the code it gives me an Exception in thread "main" java.lang.StackOverflowError
public class NQueenProblem {
final static int N = 8;
void printSolution(int board[][])
{
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++)
System.out.print(" "+board[i][j]+" ");
System.out.println();
}
}
void solveNQUtil(int board[][], int col)
{
for (int i = 0; i < N; i++) {
solveNQUtil(board, col + 1);
}
}
public static void main(String[] args) {
NQueenProblem Queen = new NQueenProblem();
int board[][] = new int[N][N];
Queen.solveNQUtil(board, 0);
}
}
Aucun commentaire:
Enregistrer un commentaire