Dor*_*ris -2 java arrays distance coordinates
我是Java新手.
如何将具有坐标(例如(x,y)的项目列表)分配给数组并计算每个项目之间的距离?
如果有人能帮忙,感激不尽!
你有什么尝试?如果您实际发布您编写的代码并展示了一些努力,那么您在这里会做得更好.
从以下开始Point:
public class Point {
private final double x;
private final double y;
public Point(x, y) {
this.x = x;
this.y = y;
}
public static double distance(Point a, Point b) {
double dx = a.x - b.x;
double dy = a.y - b.y;
return Math.sqrt(dx*dx + dy*dy);
}
}
Run Code Online (Sandbox Code Playgroud)