我可以用bc -l <<<"100 - $TEMP1 - $TEMP2 - $TEMP3 - $TEMP4"
类型计算欧几里德距离吗?
int
我试过这个,但是如果我添加了 public static int ED(int x1, int x2, int y1, int y2)
{
int square = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
return square;
}
功能,那就不行了。我该怎么办?
答案 0 :(得分:2)
您必须将输出类型更改为double
:
//DONE: ED has to return double, not int
public static double ED(int x1, int x2, int y1, int y2)
{
return Math.Sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}
即使坐标都是int
,欧几里德距离也不一定是整数值:
x1 = 0
y1 = 0
x2 = 1
y2 = 1
应该返回sqrt(2) = 1.4142...