编译的时候说需要标示符,在代码第三行,为什么,求大神。
class Point{
double x,y,z;
Point(double_x,double_y,double_z ){
x=_x;
y=_y;
z=_z;
}
void setX(double _x){
x=_x;
}
void setY(double _y){
y=_y;
}
void setZ(double_z){
z=_z;
}
double getDistance(Point P){
return(x-p.x)*(x-p.x)+(y-p.y)*(y-p.y)+(z-p.z)*(z-p.z);
}
}
public class TestPoint{
public static void main(String[]args){
Point p=new Point(1.0,2.0,3.0);
Point p1=new Point(0.0,0.0,0.0);
System.out.println(p.getdistance(p1));
p.setX(5.0);
System.out.println(p.getDistance(new point(1.0,1.0,1.0)));
}
}
java
[解决办法]
楼主您好啊!就是类型与变量之间没有间隔啊!还有就是大写的Point你写成小写了啊!还有就是方法你也写错啦!我给你改了一下代码啊!现在可以了啊!
class Point{
double x,y,z;
Point(double _x,double _y,double _z ){
x=_x;
y=_y;
z=_z;
}
void setX(double _x){
x=_x;
}
void setY(double _y){
y=_y;
}
void setZ(double _z){
z=_z;
}
double getDistance(Point P){
return(x-P.x)*(x-P.x)+(y-P.y)*(y-P.y)+(z-P.z)*(z-P.z);
}
}
public class TestPoint{
public static void main(String[]args){
Point p=new Point(1.0,2.0,3.0);
Point p1=new Point(0.0,0.0,0.0);
System.out.println(p.getDistance(p1));
p.setX(5.0);
System.out.println(p.getDistance(new Point(1.0,1.0,1.0)));
}
}