Advertisement
Guest User

Untitled

a guest
Nov 19th, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.62 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class Task14 {
  3.  
  4. public static void main(String[] args) {
  5. System.out.println("Моля, въведете координати по хоризонтала от 1 до 8 за първата позиция!");
  6. Scanner sc = new Scanner(System.in);
  7. int firstHorizontal = sc.nextInt();
  8.  
  9. System.out.println("Моля, въведете координати по вертикала от 1 до 8 за първата позиция!");
  10. int firstVertical = sc.nextInt();
  11.  
  12. System.out.println("Моля, въведете координати по хоризонтала от 1 до 8 за втората позиция!");
  13. int secondHorizontal = sc.nextInt();
  14.  
  15. System.out.println("Моля, въведете координати по вертикала от 1 до 8 за втората позиция!");
  16. int secondVertical = sc.nextInt();
  17. sc.close();
  18.  
  19. /** correct length check */
  20. if (firstHorizontal < 1 || firstHorizontal > 8 || firstVertical < 1 || firstVertical > 8){
  21. System.err.println("Въведените координати на първата позиция са грешни, моля въведете координати между 1 и 8!");
  22. }
  23. else if (secondHorizontal < 1 || secondHorizontal > 8 || secondVertical < 1 || secondVertical > 8){
  24.  
  25. System.err.println("Въведените координати на втората позиция са грешни, моля въведете координати между 1 и 8");
  26. }
  27.  
  28.  
  29. int firstCoordinate = (firstHorizontal*10)+firstVertical;
  30. int secondCoordinate = (secondHorizontal*10)+secondVertical;
  31. int firstWhite, secondWhite;
  32.  
  33. /** separating white from black positions. If white = 1 white is true*/
  34. if (firstCoordinate % 2 == 0 && (firstCoordinate/10) % 2 != 0 ){
  35. firstWhite = 1;
  36. }
  37. else if (firstCoordinate % 2 != 0 && (firstCoordinate/10) % 2 == 0){
  38. firstWhite = 1;
  39. }
  40. else{
  41. firstWhite = 0;
  42. }
  43.  
  44.  
  45. if (secondCoordinate % 2 == 0 && (secondCoordinate/10)%2 != 0){
  46. secondWhite = 1;
  47. }
  48. else if(secondCoordinate % 2 != 0 && (secondCoordinate/10) % 2 == 0){
  49. secondWhite = 1;
  50. }
  51. else{
  52. secondWhite = 0;
  53. }
  54.  
  55. if (firstWhite == secondWhite && firstWhite == 1){
  56. System.out.println("Двете позиции са с еднакъв бял цвят!");
  57. }
  58. else if(firstWhite == secondWhite && firstWhite ==0){
  59. System.out.println("Двете позиции са с еднакъв черен цвят!");
  60. }
  61. else{
  62. System.out.println("Двете позиции са с различен цвят!");
  63. }
  64. }
  65.  
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement