@@ -0,0 +1,2147 @@
+package com.problems.techiedelight;%0A%0A/**%0A * Created by Maks on 5/29/2017.%0A * http://www.techiedelight.com/print-possible-solutions-n-queens-problem/%0A */%0Apublic class NQueenProblem %7B%0A%0A    private boolean solve(int%5B%5D%5B%5D arr, int size, int col)%7B%0A%0A        if(col==size)%7B%0A            printSolution(arr, size);%0A            return true;%0A        %7D%0A%0A        for(int i=0; i%3Csize; i++)%7B%0A            if(isSafe(arr,size, i, col))%7B%0A%0A                arr%5Bi%5D%5Bcol%5D=1; //put queen%0A                solve(arr,size,col+1);%0A                arr%5Bi%5D%5Bcol%5D=0;%0A            %7D%0A%0A            return false;%0A%0A        %7D%0A%0A    %7D%0A%0A    private void printSolution(int%5B%5D%5B%5D arr, int size) %7B%0A        System.out.println();%0A        for(int i=0; i%3Csize; i++)%7B%0A            for(int j=0; j%3Csize; j++)%7B%0A                System.out.print(arr%5Bi%5D%5Bj%5D+ %22 %22);%0A            %7D%0A            System.out.println();%0A        %7D%0A%0A    %7D%0A%0A    private boolean isSafe(int%5B%5D%5B%5D arr, int size, int row, int col) %7B%0A%0A        int i,j;%0A        //check row%0A        for( i=0; i%3Csize; i++)%7B%0A            if(arr%5Brow%5D%5Bi%5D==1)%7B%0A                return  false;%0A            %7D%0A        %7D%0A%0A        //check column%0A        for( i=0; i%3Csize; i++)%7B%0A            if(arr%5Bi%5D%5Bcol%5D==1)%7B%0A                return  false;%0A            %7D%0A        %7D%0A%0A        //check diagonal on upper left side%0A        i=row;%0A        j=col;%0A        while(i%3E=0 && j%3E=0)%7B%0A            if(arr%5Bi%5D%5Bj%5D==1)%7B%0A                return  false;%0A            %7D%0A            i--;%0A            j--;%0A        %7D%0A%0A        //check diagonal upper right%0A        i=row;%0A        j=col;%0A        while(i%3Csize && j%3E=0)%7B%0A            if(arr%5Bi%5D%5Bj%5D==1)%7B%0A                return  false;%0A            %7D%0A            i++;%0A            j--;%0A        %7D%0A%0A        //check diagonal lower left%0A        i=row;%0A        j=col;%0A        while(i%3E=0 && col%3Csize)%7B%0A            if(arr%5Bi%5D%5Bj%5D==1)%7B%0A                return  false;%0A            %7D%0A            i--;%0A            j++;%0A        %7D%0A%0A        //check diagonal lower right%0A        i=row;%0A        j=col;%0A        while(i%3Csize && j%3Csize)%7B%0A            if(arr%5Bi%5D%5Bj%5D==1)%7B%0A                return  false;%0A            %7D%0A            i++;%0A            j++;%0A        %7D%0A        return  true;%0A    %7D%0A%7D%0A

NQueenProblem print all solutions