luoni

Untitled

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