publicclassPoint{ double x; double y; double z; Point(double _x, double _y, double _z){ x = _x; y = _y; z = _z; } publicvoidsetX(double _x){ x = _x; } publicvoidsetY(double _y){ y = _y; } publicvoidsetZ(double _z){ z = _z; } publicdoublegetDistance(Point p){ return Math.pow(x-p.x,2) + Math.pow(y-p.y,2) + Math.pow(y-p.y,2); }
}
classTestPoint{ publicstaticvoidmain(String[] args){ double a = 1.0, b = 2.0, c = 3.0; Point p1 = new Point(a, b, c); p1.setX(4); System.out.println(p1.getDistance(new Point(3,2,1))); } }