java完整的编程谢谢 题目如下

2025-04-01 03:10:49
推荐回答(2个)
回答1:

public class Point {
double x,y;
public Point(float x,float y ){
this.x = x;
this.y = y;
}

void setX(double x){
this.x = x;
}

void setY(double y){
this.y = y;
}

double getDistance(Point p){
return (x-p.x)*(x + p.x) +(y - p.y)*(y + p.y);
}

public static void main(String[] args) {
Point p = new Point(1,2);
Point p1 = new Point(0,0);
System.out.print(p.getDistance(p1));

p.setX(5.0);
System.out.print(p.getDistance(p1));
}

}

回答2:

看看java的Point源码