java 编写一个point类,计算两个point实例之间的距离
若以下回答无法解决问题,邀请你更新回答
1个回答
展开全部
public class Point
{
private int x;
private int y;
public Point(){x=0;y=0;}
public Point(int x, int y){this.x = x;this.y = y;}
public void setX(int x){this.x = x;}
public void setY(int y){this.y = y;}
public int getX(){return x;}
public int getY(){return y;}
public double Distance(Point p)
{
int diffx = p.getX() - this.x;
int diffy = p.getY() - this.y;
return Math.Sqrt(diffx * diffx + diffy * diffy);
}
}
{
private int x;
private int y;
public Point(){x=0;y=0;}
public Point(int x, int y){this.x = x;this.y = y;}
public void setX(int x){this.x = x;}
public void setY(int y){this.y = y;}
public int getX(){return x;}
public int getY(){return y;}
public double Distance(Point p)
{
int diffx = p.getX() - this.x;
int diffy = p.getY() - this.y;
return Math.Sqrt(diffx * diffx + diffy * diffy);
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询