public class Point
{
public int x;
public int y;
public Point(int x,int y)
{
this.x=x;
this.y=y;
}
public Point(int x)
{
this(x,x);
}
public double distance()
{
return this.distance(0,0);
}
public double distance(int x,int y)
{
return Math.sqrt((this.x-x)(this.x-x)+(this.y-y)(this.y-y));
}
public double distance(Point p)
{
return this.distance(p.x,p.y);
}
}
Point类:
public class Point {
private double xx;
private double yy;
public Point(){xx = 0;yy=0;}
public Point(double x,double y){xx =x;yy = y;}
public double getXx() {
return xx;
}
public void setXx(double xx) {
this.xx = xx;
}
public double getYy() {
return yy;
}
public void setYy(double yy) {
this.yy = yy;
}
}
PointDemo类:
public class PointDemo {
public static void main(String[] args) {
// TODO Auto-generated method stub
Point p1 = new Point(3,3);
Point p2 = new Point(4,5);
double dis = Math.sqrt((p1.getXx() - p2.getXx())*(p1.getXx() - p2.getXx()) + (p1.getYy()-p2.getYy())*(p1.getYy()-p2.getYy()));
System.out.println("两点间的距离=" + dis);
}
}