【发布时间】:2016-06-10 20:55:54
【问题描述】:
这是我的代码的一小部分。问题是无论代码将进入if 语句。
public static double value(char[][] array, int x, int y) {
for (int i = 0; i < array.length; i++) {
for (int j = 0; j < array[0].length; j++) {
if (array[i][j] == (char) 120) {
int x_cord = i;
int y_cord = j;
int width = (x_cord - x);
int height = (y_cord - y);
Math.abs(width);
Math.abs(height);
double distance = Math.sqrt(Math.pow(width, 2) + Math.pow(height, 2));
return distance;
}
}
}
}
我知道我在某处存在逻辑缺陷,我需要以某种方式告诉程序它无论如何都会到达那里,但我可以这样做吗?
【问题讨论】:
-
如果
array为空怎么办?在这种情况下,您需要返回一些东西。或者抛出异常。 -
你必须从这个方法返回。现在你只在条件为真时返回。
标签: java for-loop compiler-errors return