你好,程序如下:
public class Point {
double x,y;
double d;
Point(double a,double b){
x = a;
y = b;
}
void TestPoint(Point p1,Point p2){
x = (p1.x + p2.x)/2;
y = (p1.y + p2.y)/2;
System.out.println("(" + x + ","+ y + ")");
}
void Distance(Point p1,Point p2){
d = Math.sqrt((p1.x - p2.x)*(p1.x - p2.x) + (p1.y - p2.y)*(p1.y - p2.y));
System.out.println(d);
}
public static void main(String[] args) {
Point p = new Point(0,0);
Point p1 = new Point(1,1);
Point p2 = new Point(2,2);
p.TestPoint(p1, p2);
p.Distance(p1, p2);
}
}