Guest User

Untitled

a guest
Feb 17th, 2019
369
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.20 KB | None | 0 0
  1. package Methods;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class CenterPoint {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.  
  9.         int X1 = Integer.parseInt(scanner.nextLine());
  10.         int Y1 = Integer.parseInt(scanner.nextLine());
  11.         int X2 = Integer.parseInt(scanner.nextLine());
  12.         int Y2 = Integer.parseInt(scanner.nextLine());
  13.  
  14.         int bestX = closerToCenter(X1, X2);
  15.         int bestY = closerToCenter(Y1, Y2);
  16.  
  17.         if (Math.abs(bestX) != Math.abs(bestY)) {
  18.             if (Math.abs(X1) == Math.abs(X2) || Math.abs(Y1) == Math.abs(Y2)) {
  19.                 System.out.printf("(%d, %d)",Math.abs(bestX),Math.abs(bestY));
  20.             } else {
  21.                 System.out.printf("(%d, %d)", bestX, bestY);
  22.             }
  23.         } else {
  24.             if(Math.abs(Y1) == Math.abs(X2)) {
  25.                 System.out.printf("(%d)", bestY);
  26.             } else {
  27.                 System.out.printf("(%d)", bestX);
  28.             }
  29.         }
  30.  
  31.     }
  32.  
  33.     static int closerToCenter(int first, int second) {
  34.  
  35.  
  36.         if (Math.abs(first) <= Math.abs(second)) {
  37.  
  38.             return first;
  39.  
  40.         }
  41.  
  42.             return second;
  43.  
  44.  
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment