import java.lang.Math.hypot;
class CPoint
{
private double x;
private double y;
CPoint(double x,double y)
{
this.x = x;
this.y = y;
}
public void distance(CPoint p)
{
System.out.println("distance"+java.lang.Math.hypot(this.x-p.x,this.y-p.y));
//为什么必须这样调用hypot;明明已经import了啊
}
}
竟然出现了错误
TestCPoint.java:1: 找不到符号
符号: 类 hypot
位置: 类 java.lang.Math
import java.lang.Math.hypot;可是Math中明明有hypot这一个函数啊,在代码中显示调用则成功,真是奇怪?望有人帮忙看看
^
或者你可以使用Math.hypot来调用该静态方法。
...
System.out.println("distance"+hypot(this.x-p.x,this.y-p.y));
改为
import java.lang.Math;System.out.println("distance"+java.lang.Math.hypot(this.x-p.x,this.y-p.y));
改为
System.out.println("distance"+Math.hypot(this.x-p.x,this.y-p.y));