DanikYakush

Task27

Jul 6th, 2022 (edited)
99
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Task27 {
  2.     public static double calcDistance(Point point1, Point point2) {
  3.         return Math.sqrt((point1.x - point2.x) * (point1.x - point2.x) + (point1.y - point2.y) * (point1.y - point2.y));
  4.     }
  5.  
  6.     public static Point[] maxDistance(Point[] points) {
  7.         if (points.length == 1) {
  8.             return new Point[0];
  9.         }
  10.         Point[] a = new Point[2];
  11.         a[0] = points[0];
  12.         a[1] = points[1];
  13.         double dist = calcDistance(points[0], points[1]);
  14.         for (int i = 0; i < points.length; ++i) {
  15.             for (int j = i+1; j < points.length; ++j) {
  16.                 if (calcDistance(points[i], points[j]) > dist) {
  17.                     dist = calcDistance(points[i], points[j]);
  18.                 }
  19.             }
  20.         }
  21.         return a;
  22.     }
  23. }
  24.  
RAW Paste Data Copied