Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Main{
- public static void main(String[] args){
- int count = -1;
- int count2 = 0;
- int joey = 0;
- int a[][] = new int[9][9];
- while(joey == 0){
- System.out.println("Enter Row: ");
- Scanner scan = new Scanner(System.in);
- int r = scan.nextInt();
- System.out.println("Enter Column: ");
- Scanner scan2 = new Scanner(System.in);
- int c = scan2.nextInt();
- a[r][c]= 1;
- count++;
- if(r==0 && c==0){
- joey = 1;
- }
- }
- for(int row=1; row<=8; row++){
- for(int column=1; column<=8; column++){
- for(int i=1; i<8; i++){
- // Up Left Diagonal
- if(row-i >= 1 && column-i >= 1){
- if(a[row-i][column-i] == 1)
- count2++;
- }
- else
- break;
- // Up
- if(row-i >= 1){
- if(a[row-i][column] == 1)
- count2++;
- }
- else
- break;
- // Up Right Diagonal
- if(row-i >= 1 && column+i <= 7){
- if(a[row-i][column+i] == 1)
- count2++;
- }
- else
- break;
- // Right
- if(column-i >= 1){
- if(a[row][column-i] == 1)
- count2++;
- }
- else
- break;
- // Left
- if(column+1 <= 7){
- if(a[row][column+i] == 1)
- count2++;
- }
- else
- break;
- //Down
- if(row+i <= 7){
- if(a[row+i][column] == 1)
- count2++;
- }
- else
- break;
- // Down Left Diagonal
- if(row+i <= 7 && column-i >= 1){
- if(a[row+i][column-i] == 1)
- count2++;
- }
- else
- break;
- // Down Right Diagonal
- if(row+i <= 7 && column+i <=7){
- if(a[row+i][column+i] == 1)
- count2++;
- }
- else
- break;
- //System.out.println(count2);
- }
- if(count2 == count)
- System.out.println(row + "," + column);
- }
- }
- count2 = 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement