(几何:两点间的距离)编写程序,提示用户输入两个点(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);
    }
}


 

This moment will nap, you will have a dream; but this moment study, you will interpret a dream.
原文地址:https://www.cnblogs.com/mawenqi-barry/p/7536020.html