Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Task14 {
- public static void main(String[] args) {
- System.out.println("Моля, въведете координати по хоризонтала от 1 до 8 за първата позиция!");
- Scanner sc = new Scanner(System.in);
- int firstHorizontal = sc.nextInt();
- System.out.println("Моля, въведете координати по вертикала от 1 до 8 за първата позиция!");
- int firstVertical = sc.nextInt();
- System.out.println("Моля, въведете координати по хоризонтала от 1 до 8 за втората позиция!");
- int secondHorizontal = sc.nextInt();
- System.out.println("Моля, въведете координати по вертикала от 1 до 8 за втората позиция!");
- int secondVertical = sc.nextInt();
- sc.close();
- /** correct length check */
- if (firstHorizontal < 1 || firstHorizontal > 8 || firstVertical < 1 || firstVertical > 8){
- System.err.println("Въведените координати на първата позиция са грешни, моля въведете координати между 1 и 8!");
- }
- else if (secondHorizontal < 1 || secondHorizontal > 8 || secondVertical < 1 || secondVertical > 8){
- System.err.println("Въведените координати на втората позиция са грешни, моля въведете координати между 1 и 8");
- }
- int firstCoordinate = (firstHorizontal*10)+firstVertical;
- int secondCoordinate = (secondHorizontal*10)+secondVertical;
- int firstWhite, secondWhite;
- /** separating white from black positions. If white = 1 white is true*/
- if (firstCoordinate % 2 == 0 && (firstCoordinate/10) % 2 != 0 ){
- firstWhite = 1;
- }
- else if (firstCoordinate % 2 != 0 && (firstCoordinate/10) % 2 == 0){
- firstWhite = 1;
- }
- else{
- firstWhite = 0;
- }
- if (secondCoordinate % 2 == 0 && (secondCoordinate/10)%2 != 0){
- secondWhite = 1;
- }
- else if(secondCoordinate % 2 != 0 && (secondCoordinate/10) % 2 == 0){
- secondWhite = 1;
- }
- else{
- secondWhite = 0;
- }
- if (firstWhite == secondWhite && firstWhite == 1){
- System.out.println("Двете позиции са с еднакъв бял цвят!");
- }
- else if(firstWhite == secondWhite && firstWhite ==0){
- System.out.println("Двете позиции са с еднакъв черен цвят!");
- }
- else{
- System.out.println("Двете позиции са с различен цвят!");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement