-
Notifications
You must be signed in to change notification settings - Fork 0
/
B18.java
44 lines (40 loc) · 926 Bytes
/
B18.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import java.lang.Math;
class Point{
private double x;
private double y;
public Point(){
}
public Point(double x,double y){
this.x = x;
this.y=y;
}
public void setX(double x) {
this.x = x;
}
public void setY(double y) {
this.y = y;
}
public double getX() {
return x;
}
public double getY() {
return y;
}
public void setXY(double x,double y){
this.x = x;
this.y = y;
}
public double distance(double x,double y){
return Math.sqrt((this.x-x)*(this.x-x)+(this.y-y)*(this.y-y));
}
public double distance(Point another){
return distance(another.getX(),another.getY());
}
}
public class B18 {
public static void main(String[] args) {
Point p = new Point(2,3);
System.out.println(p.distance(2,3));
System.out.println(p.distance(3,4));
}
}