这个需要两个类,你的Point类没有写,正确却写法是:
Point类:
public class Point{
float x;
float y;
public double distance(Point that){
double xdiff=x-that.x;
double ydiff=y-that.y;
return Math.sqrt(xdiff*xdiff+ydiff*ydiff);
}
}
PointDistance类:
public class PointDistance{
public static void main(String[] args){
Point lowerleft = new Point();
Point upperright=new Point();
lowerleft.x = 0;
lowerleft.y = 0;
upperright.x = 100;
upperright.y = 100;
double d=lowerleft.distance(upperright);
System.out.println("the distance between both points is"+d);
}
}
这两个类应该在同一个文件夹下。
lowerleft.x = 0.0;
lowerleft.y = 0.0;
upperright.x = 100.0;
upperright.y = 100.0;
放错地方了。。这是在方法体中的
楼上那人说的就是了
lowerleft.x = 0.0;
lowerleft.y = 0.0;
upperright.x = 100.0;
upperright.y = 100.0;
这几个要放方法里
提示的那几句代码应该放在主方法里面吧
卸了从新装 那个东东