Darshana Salaskar Darshana Salaskar - 4 months ago 7x
Java Question

world map in terms of latitude and longitude

Provided with two locations on the world map in terms of latitude and longitude, print the distance between them. Note that the distance between two points (x1,y1) and (x2,y2) is the square root of (x2-x1)^2+(y2-y1)^2. Round up the value up to five decimal places.

Input Specification :

Input will be two points with each point containing First latitude and then longitude

Sample Input :

12.12345 80.44554

12.44554 80.12345

Sample Output :



Here you are :-

import java.util.Scanner;

    public class Distance {
        public static void main(String[] args) {
            Scanner in=new Scanner(System.in);
            double x1=0;
            double x2=0;
            double y1=0;
            double y2=0;
            double distance=0;

            System.out.println("Enter the value of x1 : ");
            System.out.println("Enter the value of y1 : ");
            System.out.println("Enter the value of x2 : ");
            System.out.println("Enter the value of y2 : ");

            distance=Math.sqrt(Math.pow((x2-x1), 2)+Math.pow((y2-y1), 2));
            System.out.printf("The distance between given coordinates is : %.5f",distance);

Do not forget to accept my answer by clicking right mark on top left corner of it. Happy Coding :)