publicclassPoint{ privateintx,y,z; publicPoint(){this(0,0,0);} /**生成具有特定座標的點*/ publicPoint(intox,intoy,intoz){setXYZ(ox,oy,oz);} //設定三個點的座標 publicvoidsetX(intx){this.x=x;} publicvoidsetY(inty){this.y=y;} publicvoidsetZ(intz){this.z=z;} publicvoidsetXYZ(intx,inty,intz){setX(x);setY(y);setZ(z);} /**該點到原點距離平方*/ publicintgetPODTO(){ returnx*x+y*y+z*z; } publicstaticvoidmain(String[]args){ Pointp=newPoint(); p.setXYZ(1,1,1); intdist=p.getPODTO(); System.out.println(dist); } }
publicclassPoint{ privateintx,y,z; publicPoint(){this(0,0,0);} /**生成具有特定座標的點*/ publicPoint(intox,intoy,intoz){setXYZ(ox,oy,oz);} //設定三個點的座標 publicvoidsetX(intx){this.x=x;} publicvoidsetY(inty){this.y=y;} publicvoidsetZ(intz){this.z=z;} publicvoidsetXYZ(intx,inty,intz){setX(x);setY(y);setZ(z);} /**該點到原點距離平方*/ publicintgetPODTO(){ returnx*x+y*y+z*z; } publicstaticvoidmain(String[]args){ Pointp=newPoint(); p.setXYZ(1,1,1); intdist=p.getPODTO(); System.out.println(dist); } }