【发布时间】:2014-09-18 09:14:29
【问题描述】:
对于下面提到的以下代码,我在“Return Cols”语句中得到了错误“Unreachable statement error”
代码计算最大剂量在生成的输出 CSV 文件中的位置
public int getPosition() {
double dose = 0.0;
double position = 0.0;
int rows = 0;
int cols = 0;
String s;
for (int j = 1; j < nz; j++) {
s = "";
for (int i = 1; i < nx; i++) {
for (DetEl det_el : det_els) {
if (det_els.get(j + i * nz).getDose() == getMaxDose()) {
i=rows;
j=cols;
}
// comma separated or Semicolon separated mentioned here
}
// prints out the stream of values in Doses table separated by Semicolon
}
}
return rows;
return cols;//unreachable statement error obtained at this position.
}
非常感谢任何帮助
【问题讨论】:
-
您的
return rows语句返回rows并结束该方法(返回给调用者,使用提供的值)。如果要返回多个值,则需要返回一个对象,例如int[]甚至更好 -Pair -
你认为
return rows; return cols;是什么意思? -
看起来您还想要
rows=i和cols=j而不是i=rows和j=cols。目前,rows和cols最后都为零,因为你从不写信给他们。
标签: java compiler-errors unreachable-code