- 已关闭。**此问题需要debugging details。当前不接受答案。
编辑问题以包含desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem。这将有助于其他人回答问题。
4小时前关门了。
Improve this question
我对Java还是个新手,不知道哪里出了问题。
import java.awt.geom.Point2D;
public class Quadrilaterals {
private Point2D[] vertices;
public Quadrilaterals(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4) {
vertices = new Point2D[4];
vertices[0] = new Point2D.Double(x1, y1);
vertices[1] = new Point2D.Double(x2, y2);
vertices[2] = new Point2D.Double(x3, y3);
vertices[3] = new Point2D.Double(x4, y4);
}
public double getPerimeter() {
double perimeter = 0;
for (int i = 0; i < 4; i++) {
perimeter += vertices[i].distance(vertices[(i + 1) % 4]);
}
return perimeter;
}
我不知道如何让它返回0以外的值。
1条答案
按热度按时间pkwftd7m1#
如果我这样调用它,它将打印
16.970562748477143