代码没有具体看过,从提示信息来看,可能是平台的识别出问题了?你把main类放到最上面看看呢
然后题目中distance的返回值是int,你用的double
import java.util.Scanner;
public class Main {
static class Point {
int x,y;
Point(int x,int y){
this.x =x;
this.y =y;
}
double Distance(Point p){
double r = Math.sqrt((p.x-x)*(p.x-x)+(p.y-y)*(p.y-y));
return r;
}
}
public static void main(String[] args) {
Point p1,p2;
int x1,y1,x2,y2;
Scanner sc = new Scanner(System.in);
x1 = sc.nextInt();
y1 = sc.nextInt();
x2 = sc.nextInt();
y2 = sc.nextInt();
p1 = new Point(x1,y1);
p2 = new Point(x2,y2);
System.out.println(p1.Distance(p2));
}
}