package com.qf.note;
public class note01 {
static class Point{
private int x;
private int y;
public Point(){}
public Point(int x, int y) {
this.x = x;
this.y = y;
}
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
public static void main(String[] args) {
//得到两个点
Point p1 = new Point(1,1);
Point p2 = new Point(2,2);
double distance = p1.getDistance(p2);
System.out.println(distance);
//使用静态方法
double distance1 = Point.getDistance(p1,p2);
System.out.println(distance1);
}
//求两点之间的距离方法
//静态方法
private static double getDistance(Point p1, Point p2) {
double temp = Math.pow(p1.getX() - p2.getX(),2) + Math.pow(p1.getY() - p2.getY(),2);
return Math.sqrt(temp);
}
//非静态方法
private double getDistance(Point p) {
double temp = Math.pow(this.getX() - p.getX(),2) + Math.pow(this.getY() - p.getY(),2);
return Math.sqrt(temp);
}
}
class Per{
Per baby;
}
}