-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChessQueenMoves.java
More file actions
40 lines (39 loc) · 1.3 KB
/
Copy pathChessQueenMoves.java
File metadata and controls
40 lines (39 loc) · 1.3 KB
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
35
36
37
38
39
40
/**
* ChessQueenMoves
*/
// import java.util.*;
public class ChessQueenMoves {
public static void main(String[] args) {
// Scanner sc = new Scanner(System.in);
int row = 8, col = 8;
int sourceRow = 2, sourceCol = 1;
int board[][] = new int[row][col];
for (int i = 0; i < row; i++) {
for (int j = 0; j < col; j++) {
if (i == sourceRow && j == sourceCol)
board[i][j] = 1;
else
board[i][j] = 0;
System.out.print(board[i][j] + " ");
}
System.out.println();
}
System.out.println();
int drow = 1, dcol = 0;
if (drow == sourceRow || sourceCol == dcol || drow + dcol == sourceRow + sourceCol
|| drow - dcol == sourceRow - sourceCol) {
System.out.println("valid");
for (int i = 0; i < row; i++) {
for (int j = 0; j < col; j++) {
if (i == drow && j == dcol)
board[i][j] = 1;
else
board[i][j] = 0;
System.out.print(board[i][j] + " ");
}
System.out.println();
}
} else
System.out.println("not valid");
}
}