Java-09,练习

 

 我的代码

public class Point {
    private int x;
    private int y;
    private int z;
    
    public Point(int _x,int _y,int _z){
        x = _x;
        y = _y;
        z = _z;
    }
    
    public void setX(int i){
        x = i;
    }
    
    public void setY(int i){
        y = i;
    }
    
    public void setZ(int i){
        z = i;
    }
    
    public double distance(){
        return Math.sqrt( x*x+y*y+z*z);
    }
    
    public static void main(String[] args) {
        Point p1 = new Point(1,2,3);
        System.out.println(p1.distance());
    }
}

 

posted @ 2020-02-23 23:31  润青  阅读(94)  评论(0编辑  收藏  举报