Java-09,练习

Posted 润青

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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());
    }
}

 

以上是关于Java-09,练习的主要内容,如果未能解决你的问题,请参考以下文章