Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package pointDistance;
- import java.util.Scanner;
- public class PointDistance {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- Scanner input = new Scanner(System.in);
- double[][] a = new double[][] { { -1, 3 }, { -1, -1 }, { 1, 1 }, { 2, 0.5 }, { 2, -1 }, { 3, 3 }, { 4, 2 },
- { 4, -0.5 } };
- double minDist = 100000;
- String indexOfMinDist = new String("");
- int startIndex = 0;
- for (int i = 0; i < a.length - 1; i++) {
- for (int j = startIndex; j < a.length - 1; j++) {
- double distance = Math.sqrt(Math.pow(a[i][0] - a[j + 1][0], 2) + Math.pow(a[i][1] - a[j + 1][1], 2));
- if (minDist > distance) {
- indexOfMinDist = "The smallest distance between point: " + a[i][0] + ", " + a[i][1] + " and point: "
- + a[j + 1][0] + ", " + a[j + 1][1] + " and the distance is " + distance;
- }
- System.out.println("Distance between point: " + a[i][0] + ", " + a[i][1] + " and point: " + a[j + 1][0]
- + ", " + a[j + 1][1] + " and the distance is " + distance);
- }
- startIndex++;
- }
- System.out.println(indexOfMinDist);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement