已调试可运行,但需要改进
package test;
public class Point {
double x,y;
static 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 + ")");
}
static 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 p1 = new Point(0,0);
Point p2 = new Point(1,3);
Point.distance(p1, p2);
}
}
package test;
public class Point {
double x,y;
static 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 + ")");
}
static 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 p1 = new Point(0,0);
Point p2 = new Point(1,3);
Point.distance(p1, p2);
}
}