Upcoming SlideShare
×

# Permainan n queen pada java

1,075 views

Published on

Published in: Technology, News & Politics
0 Likes
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

• Be the first to like this

Views
Total views
1,075
On SlideShare
0
From Embeds
0
Number of Embeds
5
Actions
Shares
0
3
0
Likes
0
Embeds 0
No embeds

No notes for slide

### Permainan n queen pada java

1. 1. DESIGN PEMODELAN DAN SIMULASI OUTPUTNYA PENERAPAN ALGORIMA KE N-QUEEN
2. 2. public class Queens { public static boolean isConsistent(int[] q, int n) { for (int i = 0; i < n; i++) { if (q[i] == q[n]) return false; // same column if ((q[i] - q[n]) == (n - i)) return false; // same major diagonal if ((q[n] - q[i]) == (n - i)) return false; // same minor diagonal } return true; }
3. 3. public static void printQueens(int[] q) { int N = q.length; for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { if (q[i] == j) System.out.print("Q "); else System.out.print("* "); } System.out.println(); } System.out.println(); }
4. 4. public static void enumerate(int N) { int[] a = new int[N]; enumerate(a, 0); } public static void main(String args[]) { Scanner S=new Scanner(System.in); System.out.print("Enter no. of Queens: "); int N = S.nextInt(); enumerate(N); } }