4个回答
展开全部
Point类Point.java
public class Point {
public Point(){}
public Point(double x, double y) {
super();
this.x = x;
this.y = y;
}
public double getX() {
return x;
}
public void setX(double x) {
this.x = x;
}
public double getY() {
return y;
}
public void setY(double y) {
this.y = y;
}
private double x = 0;
private double y = 0;
public double getDistance(Point p){
double x = p.getX() - this.x;
double y = p.getY() - this.y;
return Math.sqrt(x*x + y*y);
}
}
测试类Test.java
public class Test {
public static void main(String[] args){
Point p1 = new Point(0,0);
Point p2 = new Point(100, 0);
System.out.print(p1.getDistance(p2));
}
}
public class Point {
public Point(){}
public Point(double x, double y) {
super();
this.x = x;
this.y = y;
}
public double getX() {
return x;
}
public void setX(double x) {
this.x = x;
}
public double getY() {
return y;
}
public void setY(double y) {
this.y = y;
}
private double x = 0;
private double y = 0;
public double getDistance(Point p){
double x = p.getX() - this.x;
double y = p.getY() - this.y;
return Math.sqrt(x*x + y*y);
}
}
测试类Test.java
public class Test {
public static void main(String[] args){
Point p1 = new Point(0,0);
Point p2 = new Point(100, 0);
System.out.print(p1.getDistance(p2));
}
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
太简单了吧,定义属性x,y
声明对象
距离(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)开根号
声明对象
距离(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)开根号
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
public class Point {
public double x;
public double y;
public Point(double x, double y) {
this.x = x;
this.y = y;
}
public double distance(Point pt) {
double px = pt.x - this.x;
double py = pt.y - this.y;
return Math.sqrt(px * px + py * py);
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
double x = p1.getX() - p2.getX();
double y = p1.getY() - p2.getY();
return Math.sqrt(x*x+y*y);
double y = p1.getY() - p2.getY();
return Math.sqrt(x*x+y*y);
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询