/* Problem 2, Lab 9, Wednesday 22nd October The aim of this exercise is to experimentally find out the approximate minimum distance between points when we select n points randomly uniformly in a given interval. Create an array A of n Points in 2D space. The value of n has to be provided from command line. Now create these n points randomly by selecting their x and y coordinates from the range 0 to 400, and store their references in A. Using the Point class (refer to the notes of Lecture 22). Assuming that the Point class and Array2 are in the same package (here its the default) */ public class Array2 { public static void main(String[] args) { if (args.length != 1) { System.out.println("Invalid Command line arguements."); return; } int n; try { n = Integer.parseInt(args[0]); } catch (NumberFormatException ex) { System.out.println("Invalid Command line arguements."); return; } Point[] A = new Point[n]; double tempx, tempy; for (int i = 0; i < n; i++) { tempx = Math.random() * 400; tempy = Math.random() * 400; A[i] = new Point(tempx, tempy); } double minDistance = Double.MAX_VALUE; //initializing minDistance with +ve infinity which in this case is Double.MAX_VALUE double tempDistance = 0.0; for (int i = 0; i < n - 1; i++) { for (int j = i + 1; j < n; j++) { tempDistance = A[i].distance_from_point(A[j]); minDistance = minDistance < tempDistance ? minDistance : tempDistance; } } System.out.println("Minimum Distance between random points is :: " + minDistance); } }