forked from zhaosongbobo/java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPoint.java
More file actions
43 lines (37 loc) · 824 Bytes
/
Point.java
File metadata and controls
43 lines (37 loc) · 824 Bytes
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
/**
* @author: 马士兵教育
* @create: 2019-08-24 16:13
*/
public class Point {
int x;
int y;
//设置二维的坐标点
public void set(int xx,int yy){
x = xx;
y = yy;
}
public double calcDistance(Point p){
return Math.sqrt((p.x-x)*(p.x-x)+(p.y-y)*(p.y-y));
}
public void changePoint(Point p){
int a = p.x;
p.x = x;
x = a;
int b = p.y;
p.y = y;
y = b;
}
public void show(){
System.out.println("["+x+","+y+"]");
}
public static void main(String[] args) {
Point p1 = new Point();
p1.set(3,5);
Point p2 = new Point();
p2.set(2,4);
System.out.println(p1.calcDistance(p2));
p1.changePoint(p2);
p1.show();
p2.show();
}
}