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

JAVA学习网 2017-09-18 07:12:02
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);
    }
}

阅读(834) 评论(0)