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

Posted mawenqi

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了(几何:两点间的距离)编写程序,提示用户输入两个点(x1,y1),(x2,y2),然后显示两点间的距离,利用公式,提示:math.pow(a,0.5)=根号啊。相关的知识,希望对你有一定的参考价值。


/**
 *  需求:利用Scanner,调用Math
 *  思路:利用公式,调用Math.PI
 *   
 *  步骤:略
 */

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);//power 求开平方(0.5)
        System.out.print("The distance the two points is " + distance);
    }
}

 

 

以上是关于(几何:两点间的距离)编写程序,提示用户输入两个点(x1,y1),(x2,y2),然后显示两点间的距离,利用公式,提示:math.pow(a,0.5)=根号啊。的主要内容,如果未能解决你的问题,请参考以下文章