//一条线段包含两个端点
public class Point{ //点类
private int x, y;
public Point(int x, int y) {
this.x = x;
this.y = y;
}
public int GetX() {
return x;
}
public int GetY() {
return y;
}
}
class Line{ //线段类
private Point p1,p2; // 两端点
Line(Point a, Point b) {
p1 = new Point(a.GetX(),a.GetY()); //这里为什么不使用p1 = a; p2 = b;
p2 = new Point(b.GetX(),b.GetY());
}
public double Length() {
return Math.sqrt(Math.pow(p2.GetX()-p1.GetX(),2)
+ Math.pow(p2.GetY()-p1.GetY(),2));
}
}在上面的代码中: p1 = new Point(a.GetX(),a.GetY());
p2 = new Point(b.GetX(),b.GetY()); //这里为什么不使用p1 = a; p2 = b;
添加回答
举报
0/150
提交
取消