answersLogoWhite

0

public class NQueens {

private static int[] b = new int[8];

private static int s = 0;

static boolean unsafe(int y) {

int x = b[y];

for (int i = 1; i <= y; i++) {

int t = b[y - i];

if (t x) ? "|Q" : "|_");

}

System.out.println("|");

}

}

public static void main(String[] args) {

int y = 0;

b[0] = -1;

while (y >= 0) {

do {

b[y]++;

} while ((b[y] < 8) && unsafe(y));

if (b[y] < 8) {

if (y < 7) {

b[++y] = -1;

} else {

putboard();

}

} else {

y--;

}

}

}

}

User Avatar

Wiki User

12y ago

What else can I help you with?