-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqueens_bt1.java
More file actions
34 lines (32 loc) · 928 Bytes
/
Copy pathqueens_bt1.java
File metadata and controls
34 lines (32 loc) · 928 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
public class queens_bt1{
public static void Boardprint(char board[][]){
System.out.println("-----------chess board--------");
for(int i=0;i<board.length;i++){
for(int j=0;j<board.length;j++){
System.out.print(board[i][j] + " ");
}
System.out.println();
}
}
public static void Queensrow(char board[][], int row){
if(row==board.length){
Boardprint(board);
return;
}
for(int i=0;i<board.length;i++){
board[row][i]='Q';
Queensrow(board,row+1);
board[row][i]='X';
}
}
public static void main(String args[]){
int n=2;
char board[][]=new char[n][n];
for(int i=0;i<board.length;i++){
for(int j=0;j<board.length;j++){
board[i][j]='X';
}
}
Queensrow(board,0);
}
}