gpt4 book ai didi

Java:无法访问的语句错误

转载 作者:行者123 更新时间:2023-12-01 17:05:12 27 4
gpt4 key购买 nike

对于下面提到的以下代码,我在“Return Cols”语句中收到错误“Unreachable statements 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; // when your program reach to this your program will return
return cols; // then never comes to here

如果您想从一个方法返回多个值,您可以使用Array或您自己的Object

例如:

public int[] getPosition(){
int[] arr=new int[2];
arr[0]=rows;
arr[1]=cols;
return arr;
}

您应该阅读this .

关于Java:无法访问的语句错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25908680/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com