太自由

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
//求两点之间的距离.
import java.util.Scanner;
//import java.lang.Math;
class TestLength 
{
    public static void main(String[] args) 
    {
        double x1,x2,y1,y2;
        Scanner in = new Scanner(System.in);
        System.out.println("Please input four integer numbers:");
        x1 = in.nextDouble();
        y1 = in.nextDouble();
        x2 = in.nextDouble();
        y2 = in.nextDouble();

        //调用函数,求两点之间的距离。
        double l = Length(x1,y1,x2,y2);
        System.out.println("两点之间的距离是:"+l);
    }
    public static double Length(double x1,double y1,double x2,double y2)
    {
        double n;
        n = Math.sqrt(((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)));
        return n;
    }
}

 

posted on 2016-03-23 13:35  太自由  阅读(359)  评论(0编辑  收藏  举报