码迷,mamicode.com
首页 > 其他好文 > 详细

(几何:两点间的距离)编写程序,提示用户输入两个点(x1,y1),(x2,y2),然后显示两点间的距离,利用公式,提示:math.pow(a,0.5)=根号啊。

时间:2017-09-17 17:33:59      阅读:157      评论:0      收藏:0      [点我收藏+]

标签:port   color   image   stat   blog   str   next   distance   rgs   

import java.util.Scanner;
public class Demo_1{
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        System.out.print("Enter x1 and y1: ");
        System.out.print("Enter x2 and y2: ");
        double b=input.nextDouble();
        double d=input.nextDouble();
        double a=input.nextDouble();
        double c=input.nextDouble();
                
        double  y= (b-a)*(b-a)+(d-c)*(d-c);
        double distance = Math.pow(y, 0.5);
        System.out.print("The distance the two points is " + distance);
    }
}

技术分享

(几何:两点间的距离)编写程序,提示用户输入两个点(x1,y1),(x2,y2),然后显示两点间的距离,利用公式,提示:math.pow(a,0.5)=根号啊。

标签:port   color   image   stat   blog   str   next   distance   rgs   

原文地址:http://www.cnblogs.com/mawenqi-barry/p/7536020.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!