This is what I need my program to do:
1. Ask the user to enter the number of points.
2. Ask the user to enter x and y positions for each point. Store the positions in a 2-D array. What should the dimensions of the 2-D array be?
3. Compute the distance between the first two points and initialize the variable that represents the shortest distance. Recall that the distance between the two points (x1, y1) and (x2, y2) is computed by taking the square root of the quantity (x1 - x2)^2 + (y1 - y2)^2.
4. Use a nested for loop to compute the distance for every two points and update the shortest distance and the two points with the shortest distance.
5. Display the shortest distance and the closest two points.
This is where I have gotten so far, when I run it and calculate the distance I just get 0.0 every time.
//*****************************************************************************************************************************************
// Find Nearest Points
//
// The GPS navigation system uses the graph and geometric algorithms to calculate distances and map a route.
// One of the geometric problems is the closest-pair problem. Given a set of points,
// the closest-pair problem is to find the two points that are nearest to each otherThe GPS navigation system uses
// the graph and geometric algorithms to calculate distances and map a route. One of the geometric problems
// is the closest-pair problem. Given a set of points, the closest-pair problem is to find the two points that are nearest to each other
//
//
//*****************************************************************************************************************************************
import java.util.Scanner;
public class Points
{
public static void main(String[] agrs)
{
int x1, x2, y1, y2;
int[][] table = new int[2][2];
Scanner scan = new Scanner(System.in);
for (x1=1; x1<table.length; x1++){
System.out.println("Enter x1:");
table[x1][0] = scan.nextInt();
}
for (x2=1; x2<table.length; x2++){
System.out.println("Enter x2:");
table[x2][0] = scan.nextInt();
}
for (y1=1; y1<table.length; y1++){
System.out.println("Enter y1:");
table[0][y1] = scan.nextInt();
}
for (y2=1; y2<table.length; y2++){
System.out.println("Enter y2:");
table[0][y2] = scan.nextInt();
}
double x = x1 - x2;
double y = y1 - y2;
double distance = Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2));
System.out.println(+ distance);
}
}