救助八皇后JAVA程序代码

来源:百度知道 编辑:UC知道 时间:2024/09/21 04:33:16
用JAVA编写的八皇后程序代码

public class demo {
public static int N = 0;
public static int ROW = 8;
public int[][] chase = new int[demo.ROW][demo.ROW];
public demo() {
for (int i = 0; i < demo.ROW; i++)
for (int j = 0; j < demo.ROW; j++)
chase[i][j] = 0;
}
public void copy(int[][] k, int[][] l) {
for (int i = 0; i < demo.ROW; i++)
for (int j = 0; j < demo.ROW; j++)
l[i][j] = k[i][j];
}
public void changeChase(int[][] chase, int row, int i) {
for (int j = 1; j < demo.ROW; j++) {
chase[row][j] = 1;
chase[j][i] = 1;
}
for (int j = 1; j < demo.ROW; j++) {
if (row - j >= 0 && i - j >= 0)
chase[row - j][i - j] = 1;
if (row + j <= 7 && i - j >= 0)
chase[row + j][i - j] =