将以下方法添加到Point类:
公共距离(其他点)
返回当前Point对象与给定的另一个Point对象之间的距离。两点之间的距离等于它们的x坐标和y坐标之差的平方和的平方根。换句话说,两个点(x1,y1)和(x2,y2)之间的距离可以表示为(x2-x1)2 +(y2-y1)2的平方根。具有相同(x,y)坐标的两个点应该返回0.0的距离。
public class Point {
int x;
int y;
// // your code goes here
}
这有效:
public double distance(Point other){
return Math.sqrt((this.x-other.x)*(this.x-other.x) + (this.y-other.y)*(this.y-other.y));
}
这不是:
public double distance(Point other){
return Math.sqrt((this.x-other.x)^2 + (this.y-other.y)^2);
}
请问为什么? TY
答案 0 :(得分:0)
要将其从未回答的问题列表中删除,因为我认为这不是错字:
^
不是“授权”,而是XOR。