答案家

 找回密码
 立即注册
查看: 1245|回复: 0

用java编程实现求最大圆的距离源码答案

[复制链接]

1万

主题

1万

帖子

80万

积分

校长

Rank: 9Rank: 9Rank: 9

积分
809492
发表于 2016-12-24 15:45:00 | 显示全部楼层 |阅读模式
package nameyu;import java.util.Scanner;public class Test {
    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner input=new Scanner(System.in);
        System.out.print("Enter point 1(latitude and longitude) in degress ");
        String s1=input.nextLine();
        System.out.print("Enter point 2(latitude and longitude) in degress ");
        String s2=input.nextLine();
        double x1=Double.parseDouble(s1.split(",")[0]);
        //因为运行实例是用逗号隔开,所以这里也用逗号吧,这个split课本中可能漏讲了,自己补充吧
        double y1=Double.parseDouble(s1.split(",")[1]);
        double x2=Double.parseDouble(s2.split(",")[0]);
        double y2=Double.parseDouble(s2.split(",")[1]);
        final double   r=6371.01;
        double result=r*Math.acos(Math.sin(Math.toRadians(x1))*Math.sin(Math.toRadians(x2))+Math.cos(Math.toRadians(x1))*Math.cos(Math.toRadians(x2))*Math.cos(Math.toRadians(y1-y2)));
        System.out.println("The distance between the two points is "+result+"km");
    }
    }   

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

CopyRight(c)2016 www.daanjia.com All Rights Reserved. 本站部份资源由网友发布上传提供,如果侵犯了您的版权,请来信告知,我们将在5个工作日内处理。
快速回复 返回顶部 返回列表