程序报错缺少返回语句是什么原因?怎么解决?

xy678910 2019-12-03 05:25:38
class Line {
Point start; // Start point of line
Point end; // End point of line

// Create a line from two points
Line(final Point start, final Point end) {
this.start = new Point(start);
this.end = new Point(end);
}

// Create a line from two coordinate pairs
Line(double xStart, double yStart, double xEnd, double yEnd) {
start = new Point(xStart, yStart); // Create the start point
end = new Point(xEnd, yEnd); // Create the end point
}

// Calculate the length of a line
double length() {
return start.distance(end); // Use the method from the Point class
}

// Convert a line to a string
public String toString() {
return "(" + start + "):(" + end + ")"; // As"(start):(end)"
} // that is,"(x1,y1):(x2,y2)"

// Return a point as the intersection of two lines
Point intersects(final Line line1) {
Point localPoint = new Point(0, 0);
double num = (this.end.y - this.start.y) * (this.start.x - line1.start.x) -
(this.end.x - this.start.x) * (this.start.y - line1.start.y);
double denom = (this.end.y - this.start.y) * (line1.end.x - line1.start.x) -
(this.end.x - this.start.x) * (line1.end.y - line1.start.y);
localPoint.x = line1.start.x + (line1.end.x - line1.start.x) * num / denom;
localPoint.y = line1.start.y + (line1.end.y - line1.start.y) * num / denom;
}
}
Error:(36, 5) java: 缺少返回语句
...全文
327 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
[code=java]Point intersects(final Line line1) { Point localPoint = new Point(0, 0); double num = (this.end.y - this.start.y) * (this.start.x - line1.start.x) - (this.end.x - this.start.x) * (this.start.y - line1.start.y); double denom = (this.end.y - this.start.y) * (line1.end.x - line1.start.x) - (this.end.x - this.start.x) * (line1.end.y - line1.start.y); localPoint.x = line1.start.x + (line1.end.x - line1.start.x) * num / denom; localPoint.y = line1.start.y + (line1.end.y - line1.start.y) * num / denom; return localPoint; } 最后没有返回Point结果,在方法内最后加一行
hwj运维之路 2019-12-03
  • 打赏
  • 举报
回复
Point intersects(final Line line1) {
Point localPoint = new Point(0, 0);
double num = (this.end.y - this.start.y) * (this.start.x - line1.start.x) -
(this.end.x - this.start.x) * (this.start.y - line1.start.y);
double denom = (this.end.y - this.start.y) * (line1.end.x - line1.start.x) -
(this.end.x - this.start.x) * (line1.end.y - line1.start.y);
localPoint.x = line1.start.x + (line1.end.x - line1.start.x) * num / denom;
localPoint.y = line1.start.y + (line1.end.y - line1.start.y) * num / denom;
}

最后没有返回Point结果,加一行吧
return localPoint;

62,621

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧