From e6b7eb8b7fc27a454d860d5c2e4de98168d727eb Mon Sep 17 00:00:00 2001 From: Manik <136838380+Manik1811@users.noreply.github.com> Date: Mon, 16 Oct 2023 23:03:20 +0530 Subject: [PATCH] Create NQueen_Problem.java N Queen problem using java #1959 --- Java_Programs-master/NQueen_Problem.java | 47 ++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 Java_Programs-master/NQueen_Problem.java diff --git a/Java_Programs-master/NQueen_Problem.java b/Java_Programs-master/NQueen_Problem.java new file mode 100644 index 00000000..e9278200 --- /dev/null +++ b/Java_Programs-master/NQueen_Problem.java @@ -0,0 +1,47 @@ +//N Queen problem using java #1959 +class NQueen_Problem{ + public static boolean isSafe(char chessBoard[][],int row,int col){ + //vertical up + for(int i=row-1;i>=0;i--){ + if(chessBoard[i][col]=='Q'){ + return false; + } + } + //left diag up + for(int i=row-1,j=col-1;i>=0 && j>=0;i--,j--){ + if(chessBoard[i][j]=='Q'){ + return false; + } + } + //right diag up + for(int i=row-1,j=col+1;i>=0 && j