疯狂java


您现在的位置: 疯狂软件 >> 新闻资讯 >> 正文

求两点之间的距离,类中有静变量和静态方法


 

已调试可运行,但需要改进

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);
}


}