java问题..谢谢lass Point { double x,y,z; Point(double _x,double _y,double _z) { x = _x; y = _y;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;}double getDistance(Point p) {return
来源:学生作业帮助网 编辑:六六作业网 时间:2024/11/13 04:17:30
java问题..谢谢lass Point { double x,y,z; Point(double _x,double _y,double _z) { x = _x; y = _y;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;}double getDistance(Point p) {return
java问题..谢谢lass Point { double x,y,z; Point(double _x,double _y,double _z) { x = _x; y = _y;
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;
}
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)));
}
}
其中这个方法中只有一个参数P:double getDistance(Point p)
那么下面的System.out.println(p.getDistance(new Point(1.0,1.0,1.0)));怎么把new Point的3个数给了那个getDistance里面的P..3个数怎么给一个参数?
java问题..谢谢lass Point { double x,y,z; Point(double _x,double _y,double _z) { x = _x; y = _y;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;}double getDistance(Point p) {return
new Point(x,y,z)
这是一个Point 的对象吧
而getDistance 的参数不是一个数或三个数,是Point的一个对象