java program to calculate distance between two points

Solutions on MaxInterview for java program to calculate distance between two points by the best coders in the world

showing results for - "java program to calculate distance between two points"
Elisa
01 Jan 2017
1import java.util.Scanner;
2
3public class Main {
4
5    public static void main(String[] args) {
6
7        // distance between two points
8
9        Scanner scanner = new Scanner(System.in);
10
11        System.out.print("Enter coordinates of first point (x1,y1): ");
12        int x1 = scanner.nextInt(), y1 = scanner.nextInt();
13
14        System.out.print("Enter coordinates of second point (x2,y2): ");
15        int x2 = scanner.nextInt(), y2 = scanner.nextInt();
16
17        double distance = Math.sqrt( Math.pow(x2 - x1 ,2) + Math.pow(y2 - y1, 2) );
18
19        System.out.println("Distance between the points is " + distance);
20    }
21}