luoni

Center Point 100/100

May 25th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. package Mathods;
  2.  
  3. import java.text.DecimalFormat;
  4. import java.util.Scanner;
  5.  
  6. public class CenterPoint {
  7. public static void main(String[] args) {
  8. Scanner scanner = new Scanner(System.in);
  9. double x1 = Double.parseDouble(scanner.nextLine());
  10. double y1 = Double.parseDouble(scanner.nextLine());
  11. double x2 = Double.parseDouble(scanner.nextLine());
  12. double y2 = Double.parseDouble(scanner.nextLine());
  13. GetClosestToZero(x1, y1, x2, y2);
  14. }
  15.  
  16. static void GetClosestToZero(double x1, double y1, double x2, double y2) {
  17. DecimalFormat df = new DecimalFormat("0.###########");
  18.  
  19. if ( Math.sqrt(x1*x1 + y1*y1) <= Math.sqrt(x2*x2 + y2*y2)) {
  20. System.out.printf("(%s, %s)", df.format(x1), df.format(y1));
  21. } else {
  22. System.out.printf("(%s, %s)", df.format(x2), df.format(y2));
  23. }
  24. }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment