求两点之间的距离,见如下代码
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Point originPoint = new Point();
Scanner scanner = new Scanner(System.in);
double x = scanner.nextDouble();
double y = scanner.nextDouble();
Point point = new Point(x,y);
System.out.println("The point's x is "+point.getX()+" and point's y is "+point.getY());
System.out.printf("The distance from point to origin is:%.3f%n",point.calDistance(originPoint));
point.moveTo(20,10);
System.out.printf("After move,the distance from point to origin is:%.3f ",point.calDistance(originPoint));
}
}
public class Point {
private double x;
private double y;
public Point(){
}
public Point(double x,double y){
this.x=x;
this.y=y;
}
public double getX() {
return x;
}
public double getY() {
return y;
}
public void moveTo(double x,double y){
this.x = x;
this.y = y;
}
public double calDistance(Point target){
double x1 = this.x- target.getX();
double y1 = this.y- target.getY();
return Math.pow(x1*x1+y1*y1,0.5);
}
}
问题:1.在Point类中的calDistance方法形参中target和方法中的target.getX()的target是什么意思,以及target.getX()是什么意思,这是在调用哪里的x,
2. System.out.printf("The distance from point to origin is:%.3f%n",point.calDistance(originPoint));该句的实参为什么是originPoint,这是什么意思,是传入了几个参数?