Advertisement
Guest User

Untitled

a guest
Feb 24th, 2013
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Scanner;
  2. public class Main{
  3. public static void main(String[] args){
  4. int countofinputs = -1;
  5. int countofpiecesfound = 0;
  6. int endinput = 0;
  7. int a[][] = new int[9][9];
  8. while(endinput == 0){
  9. System.out.println("Enter Row: ");
  10. Scanner scan = new Scanner(System.in);
  11. int r = scan.nextInt();
  12. System.out.println("Enter Column: ");
  13. Scanner scan2 = new Scanner(System.in);
  14. int c = scan2.nextInt();
  15. a[r][c]= 1;
  16. countofinputs++;
  17. if(r==0 && c==0){
  18. endinput = 1;
  19. }
  20. }
  21. for(int row=1; row<=7; row++){
  22. for(int column=1; column<=7; column++){
  23. // Up Left Diagonal
  24. for(int i=1; i<7; i++){
  25. if(row-i >= 1 && column-i >= 1){
  26. if(a[row-i][column-i] == 1)
  27. countofpiecesfound++;
  28. }
  29. else
  30. break;
  31. }
  32. // Up
  33. for(int i=1; i<7; i++){
  34. if(row-i >= 1){
  35. if(a[row-i][column] == 1)
  36. countofpiecesfound++;
  37. }
  38. else
  39. break;
  40. }
  41. // Up Right Diagonal
  42. for(int i=1; i<7; i++){
  43. if(row-i >= 1 && column+i <= 7){
  44. if(a[row-i][column+i] == 1)
  45. countofpiecesfound++;
  46. }
  47. else
  48. break;
  49. }
  50. // Right
  51. for(int i=1; i<7; i++){
  52. if(column-i >= 1){
  53. if(a[row][column-i] == 1)
  54. countofpiecesfound++;
  55. }
  56. else
  57. break;
  58. }
  59. // Left
  60. for(int i=1; i<7; i++){
  61. if(column+1 <= 7){
  62. if(a[row][column+i] == 1)
  63. countofpiecesfound++;
  64. }
  65. else
  66. break;
  67. }
  68. //Down
  69. for(int i=1; i<7; i++){
  70. if(row+i <= 7){
  71. if(a[row+i][column] == 1)
  72. countofpiecesfound++;
  73. }
  74. else
  75. break;
  76. }
  77. // Down Left Diagonal
  78. for(int i=1; i<7; i++){
  79. if(row+i <= 7 && column-i >= 1){
  80. if(a[row+i][column-i] == 1)
  81. countofpiecesfound++;
  82. }
  83. else
  84. break;
  85. }
  86. // Down Right Diagonal
  87. for(int i=1; i<7; i++){
  88. if(row+i <= 7 && column+i <=7){
  89. if(a[row+i][column+i] == 1)
  90. countofpiecesfound++;
  91. }
  92. else
  93. break;
  94. }
  95. if(countofpiecesfound == countofinputs)
  96. System.out.println(row + "," + column);
  97. }
  98. countofpiecesfound = 0;
  99. }
  100. }
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement