java求两点距离
发布网友
发布时间:2022-05-14 15:23
我来回答
共1个回答
热心网友
时间:2023-08-01 05:57
public class Point {
private double x;
private double y;
public Point(double x, double y) {
this.x = x;
this.y = y;
}
public double getDistance(Point p){
double _x = Math.abs(this.x - p.x);
double _y = Math.abs(this.y - p.y);
return Math.sqrt(_x*_x+_y*_y);
}
public static void main(String[] args) {
Point p1 = new Point(5, 5);
Point p2 = new Point(10, 10);
System.out.println(p2.getDistance(p1));
}
}追问能不能说一下每一步是什么意思啊,尤其是double _x = Math.abs(this.x - p.x);
看不懂耶