两个坐标之间的距离!
1 class XYPoint{ 2 double x; 3 double y; 4 public void setX(double x){ 5 this.x = x; 6 } 7 public void setY(double y){ 8 this.y = y; 9 } 10 public double getX(){ 11 return x; 12 } 13 public double getY(){ 14 return y; 15 } 16 public void getDistence(XYPoint p){ 17 double d = Math.sqrt((this.x-p.x)*(this.x-p.x)+(this.y-p.y)*(this.y-p.y)); 18 System.out.println(d); 19 } 20 } 21 22 class Demo{ 23 public static void main(String[] args){ 24 XYPoint xy = new XYPoint(); 25 XYPoint xy1 = new XYPoint(); 26 xy.setX(1); 27 xy.setY(1); 28 xy1.setX(3); 29 xy1.setY(3); 30 xy.getDistence(xy1); 31 } 32 }