编写Point类,有两个属性x、y,一个方法distance(Point p1,Point p2),计算两者之间的距离

public class Point {
	private double x;
	private double y;

	public Point() {}
	public Point(double x,double y) {
		this.x = x;
		this.y = y;
	}
	public static double distance(Point p1,Point p2) {
		return  Math.sqrt((Math.pow(p1.x-p2.x,2)
				+Math.pow(p2.y-p1.y,2)));

	}
	public static void main(String[] args) {
		Point p1 = new Point(1,2);
		Point p2 = new Point(0,0);
		System.out.println(Point.distance(p1 ,p2));
	}

}

猜你喜欢

转载自blog.csdn.net/qq_38900441/article/details/80658064