计算两点间的公式是 =
注意:可以使用Math.pow(a,0.5)来计算
![]()
下面是一个运算示例:
Enter x1 and y1: 1.5 -3.4
Enter x1 and y2: 4 5
The distance between the two points is 8.764131445842194
package Second;
import java.util.Scanner;
public class Code_15 {
public static void main(String[] args) {
System.out.print("Enter x1 and y1:");
Scanner input = new Scanner(System.in);
double x1 = input.nextDouble();
double y1 = input.nextDouble();
System.out.println("Enter x1 and y2:");
double x2 = input.nextDouble();
double y2 = input.nextDouble();
double a= Math.pow(x2 - x1, 2) + Math.pow(y2 - y1,2);
System.out.println("The distance between the two points is " + Math.pow(a,0.5));
}
}
输出
Enter x1 and y1:1.5 -3.4 Enter x1 and y2: 4 5 The distance between the two points is 8.764131445842194