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 countofinputs = -1;
- int countofpiecesfound = 0;
- int endinput = 0;
- int a[][] = new int[9][9];
- while(endinput == 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;
- countofinputs++;
- if(r==0 && c==0){
- endinput = 1;
- }
- }
- for(int row=1; row<=7; row++){
- for(int column=1; column<=7; column++){
- // Up Left Diagonal
- for(int i=1; i<7; i++){
- if(row-i >= 1 && column-i >= 1){
- if(a[row-i][column-i] == 1)
- countofpiecesfound++;
- }
- else
- break;
- }
- // Up
- for(int i=1; i<7; i++){
- if(row-i >= 1){
- if(a[row-i][column] == 1)
- countofpiecesfound++;
- }
- else
- break;
- }
- // Up Right Diagonal
- for(int i=1; i<7; i++){
- if(row-i >= 1 && column+i <= 7){
- if(a[row-i][column+i] == 1)
- countofpiecesfound++;
- }
- else
- break;
- }
- // Right
- for(int i=1; i<7; i++){
- if(column-i >= 1){
- if(a[row][column-i] == 1)
- countofpiecesfound++;
- }
- else
- break;
- }
- // Left
- for(int i=1; i<7; i++){
- if(column+1 <= 7){
- if(a[row][column+i] == 1)
- countofpiecesfound++;
- }
- else
- break;
- }
- //Down
- for(int i=1; i<7; i++){
- if(row+i <= 7){
- if(a[row+i][column] == 1)
- countofpiecesfound++;
- }
- else
- break;
- }
- // Down Left Diagonal
- for(int i=1; i<7; i++){
- if(row+i <= 7 && column-i >= 1){
- if(a[row+i][column-i] == 1)
- countofpiecesfound++;
- }
- else
- break;
- }
- // Down Right Diagonal
- for(int i=1; i<7; i++){
- if(row+i <= 7 && column+i <=7){
- if(a[row+i][column+i] == 1)
- countofpiecesfound++;
- }
- else
- break;
- }
- if(countofpiecesfound == countofinputs)
- System.out.println(row + "," + column);
- }
- countofpiecesfound = 0;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement