point类求两点间的距离,点到原点的距离

package zzy;
import static java.lang.Math.pow;
import static java.lang.Math.sqrt;
import static java.lang.System.*;

public class point {
    public static void main(String[] args){
        point dian = new point(24,7);
        out.println(dian.distence(18,12));
        dian.distence();
    }
    private int x;
    private int y;
    public point(int x,int y){
        this.x = x;
        this.y = y;
    }
    public void show(){
        out.println("("+x+","+y+")");
    }
    public double distence(double x ,double y){
        double a_ = sqrt(pow(this.x-x,2)+pow(this.y-y,2)); 
        return(a_);
    }
    public void distence()
    {
        out.println(sqrt(pow(this.x,2)+pow(this.y,2)));
    }
}

你可能感兴趣的:(java自学笔记)