This commit is contained in:
louiscklaw
2025-02-01 01:58:47 +08:00
parent b3da7aaef5
commit 04dbefcbaf
1259 changed files with 280657 additions and 0 deletions

View File

@@ -0,0 +1,7 @@
public class Ex7 {
public static void main(String[] args) {
Point p1 = new Point(4, 5);
Point p2 = new Point(11, 4);
System.out.println("Distance = " + p1.distance(p2));
}
}

View File

@@ -0,0 +1,28 @@
public class Point {
private int x;
private int y;
public Point() {
this(0, 0);
}
public Point(int x, int y) {
setPoint(x, y);
}
public void setPoint(int x, int y) {
if (x>=0 && y>=0) {
this.x = x;
this.y = y;
}
}
public int getX() { return x; }
public int getY() { return y; }
public double distance(Point p) {
return Math.sqrt((x-p.x)*(x-p.x) + (y-p.y)*(y-p.y));
}
}