Advertisement
Guest User

Untitled

a guest
Feb 24th, 2013
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class Main{
  3. public static void main(String[] args){
  4. int count = -1;
  5. int count2 = 0;
  6. int joey = 0;
  7. int a[][] = new int[9][9];
  8. while(joey == 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. count++;
  17. if(r==0 && c==0){
  18. joey = 1;
  19. }
  20. }
  21. for(int row=1; row<=8; row++){
  22. for(int column=1; column<=8; column++){
  23. for(int i=1; i<8; i++){
  24. // Up Left Diagonal
  25. if(row-i >= 1 && column-i >= 1){
  26. if(a[row-i][column-i] == 1)
  27. count2++;
  28. }
  29. else
  30. break;
  31. // Up
  32. if(row-i >= 1){
  33. if(a[row-i][column] == 1)
  34. count2++;
  35. }
  36. else
  37. break;
  38. // Up Right Diagonal
  39. if(row-i >= 1 && column+i <= 7){
  40. if(a[row-i][column+i] == 1)
  41. count2++;
  42. }
  43. else
  44. break;
  45. // Right
  46. if(column-i >= 1){
  47. if(a[row][column-i] == 1)
  48. count2++;
  49. }
  50. else
  51. break;
  52. // Left
  53. if(column+1 <= 7){
  54. if(a[row][column+i] == 1)
  55. count2++;
  56. }
  57. else
  58. break;
  59. //Down
  60. if(row+i <= 7){
  61. if(a[row+i][column] == 1)
  62. count2++;
  63. }
  64. else
  65. break;
  66. // Down Left Diagonal
  67. if(row+i <= 7 && column-i >= 1){
  68. if(a[row+i][column-i] == 1)
  69. count2++;
  70. }
  71. else
  72. break;
  73. // Down Right Diagonal
  74. if(row+i <= 7 && column+i <=7){
  75. if(a[row+i][column+i] == 1)
  76. count2++;
  77. }
  78. else
  79. break;
  80. //System.out.println(count2);
  81. }
  82. if(count2 == count)
  83. System.out.println(row + "," + column);
  84. }
  85. }
  86. count2 = 0;
  87. }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement