4.写一个Point类,计算两个Point实例之间的距离.求java程序、

如题所述

第1个回答  2014-09-15
class Point{
public Point(int x,int y)
{
this.x = x;
this.y = y;
}
private int x;
private int y;
public float compute(Point p)
{
return Math.sqrt((p.x-this.x)^2-(p.y-this.y)^2);
}
}

距离 = new Point(3,4).compute(new Point(6,8)) = 5本回答被提问者和网友采纳
第2个回答  2014-09-15
class Point{
    private int x;
    private int y;
    public Point(int x,int y){
        this.x = x;
        this.y = y;
    } 
    public double distance(Point p){
         return Math.sqrt(Math.pow(p.x-this.x, 2)+Math.pow(p.y-this.y, 2));
    }
}

相似回答