箬珩 2022-05-31 14:01 采纳率: 100%
浏览 45
已结题

关于java类与对象的问题,

img

img


修改了很多次,还是错误

img


晕 好晕 我晕
import java.util.Scanner;
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 class Main {
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));
}
}

  • 写回答

3条回答 默认 最新

  • 摆烂熊猫 2022-05-31 15:51
    关注

    代码没有具体看过,从提示信息来看,可能是平台的识别出问题了?你把main类放到最上面看看呢

    然后题目中distance的返回值是int,你用的double

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

问题事件

  • 系统已结题 6月8日
  • 已采纳回答 5月31日
  • 创建了问题 5月31日