/** * Unit tests the {@code ClosestPair} data type. * Reads in an integer {@code n} and {@code n} points (specified by * their <em>x</em>- and <em>y</em>-coordinates) from standard input; * computes a closest pair of points; and prints the pair to standard * output. * * @param args the command-line arguments */ public static void main(String[] args) { int n = StdIn.readInt(); Point2D[] points = new Point2D[n]; for (int i = 0; i < n; i++) { double x = StdIn.readDouble(); double y = StdIn.readDouble(); points[i] = new Point2D(x, y); } ClosestPair closest = new ClosestPair(points); StdOut.println(closest.distance() + " from " + closest.either() + " to " + closest.other()); }
/**/ public static void main(string[] strarr) { int num = StdIn.readInt(); Point2D[] array = new Point2D[num]; for (int i = 0; i < num; i++) { double d = StdIn.readDouble(); double d2 = StdIn.readDouble(); array[i] = new Point2D(d, d2); } ClosestPair closestPair = new ClosestPair(array); StdOut.println(new StringBuilder().append(closestPair.distance()).append(" from ").append(closestPair.either()).append(" to ").append(closestPair.other()).toString()); }