展开全部
主方法:public class PointDis {
public static void main(String[] args) {
// TODO Auto-generated method stub
Point p1=new Point();
Point p2=new Point();
p1.setPoint(1, 1);
p2.setPoint(4, 5);
System.out.println(MyMath.distance(p1, p2));
}
}
Point类:public class Point {
private double x,y;
public void setPoint(double x,double y) {
this.x=x;
this.y=y;
}
public double getX() {
return x;
}
public double getY() {
return y;
}
}
MyMath类://这个类是32313133353236313431303231363533e59b9ee7ad9431333365653239关键public class MyMath {
static double distance;
public static double distance(Point p1,Point p2){
double x=p2.getX()-p1.getX(); //两个坐标x差
double y=p2.getY()-p1.getY(); //两个坐标y差
distance=Math.sqrt(x*x+y*y); //距离计算公式(勾股定理)
return distance;
}
}