Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Methods;
- import java.util.Scanner;
- public class CenterPoint {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int X1 = Integer.parseInt(scanner.nextLine());
- int Y1 = Integer.parseInt(scanner.nextLine());
- int X2 = Integer.parseInt(scanner.nextLine());
- int Y2 = Integer.parseInt(scanner.nextLine());
- int bestX = closerToCenter(X1, X2);
- int bestY = closerToCenter(Y1, Y2);
- if (Math.abs(bestX) != Math.abs(bestY)) {
- if (Math.abs(X1) == Math.abs(X2) || Math.abs(Y1) == Math.abs(Y2)) {
- System.out.printf("(%d, %d)",Math.abs(bestX),Math.abs(bestY));
- } else {
- System.out.printf("(%d, %d)", bestX, bestY);
- }
- } else {
- if(Math.abs(Y1) == Math.abs(X2)) {
- System.out.printf("(%d)", bestY);
- } else {
- System.out.printf("(%d)", bestX);
- }
- }
- }
- static int closerToCenter(int first, int second) {
- if (Math.abs(first) <= Math.abs(second)) {
- return first;
- }
- return second;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment