世界地图的纬度和经度

时间:2016-05-27 12:11:39

标签: java

在纬度和经度方面,在世界地图上提供两个位置,打印它们之间的距离。注意,两点(x1,y1)和(x2,y2)之间的距离是(x2-x1)^ 2 +(y2-y1)^ 2的平方根。将值向上舍入到小数点后五位。

输入规范:

输入将是两个点,每个点包含第一纬度,然后是经度

示例输入:

12.12345 80.44554

12.44554 80.12345

示例输出:

0.45550

1 个答案:

答案 0 :(得分:0)

你在这里: -

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 : ");
            x1=in.nextDouble();
            System.out.println("Enter the value of y1 : ");
            y1=in.nextDouble();
            System.out.println("Enter the value of x2 : ");
            x2=in.nextDouble();
            System.out.println("Enter the value of y2 : ");
            y2=in.nextDouble();

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