Javaç¨åºï¼
class Point {
protected double x;
protected double y;
public Point() {
x = 0;
y = 0;
}
public Point(double x, double y) {
this.x = x;
this.y = y;
}
public static double distance(Point p1, Point p2) {
return Math.sqrt(Math.pow(p1.x - p2.x, 2) + Math.pow(p1.y - p2.y, 2));
}
}
public class Main {
public static void main(String[] args) {
Point p1 = new Point(0, 0);
Point p2 = new Point(1, 2);
System.out.println("p1ãp2两ç¹ä¹é´çè·ç¦»ï¼" + Point.distance(p1, p2));
}
}
è¿è¡æµè¯ï¼
p1ãp2两ç¹ä¹é´çè·ç¦»ï¼2.23606797749979