main类怎么定义啊
编程求两点间的距离,要求定义一个Distance类,在该类中声明两点的位置a(x1,y1)和b(x2,y2),定义方法getDistance()实现距离的计算。
回复 楼主 dayan88ka
程序代码:public class Distance {
public static void main(String[] args) {
Point pointA = new Point(0, 0);
Point pointB = new Point(4, 3);
Double dis = getDistance(pointA, pointB);
System.out.println("pointA: (" + pointA.x + ", " + pointA.y + ")");
System.out.println("pointB: (" + pointB.x + ", " + pointB.y + ")");
System.out.println("A-B距离: " + dis);
}
private static Double getDistance(Point pointA, Point pointB) {
return Math.pow((Math.pow((pointB.y - pointA.y), 2) + Math.pow((pointB.x - pointA.x), 2)), 0.5);
}
}
class Point {
double x;
double y;
public Point(double x, double y) {
this.x = x;
this.y = y;
}
}










