在 Eclipse Java IDE 给我 continue 语句带来麻烦时出现错误:
double sum = 0.0;
double avg = 0.0;
for (i=0 ; i<daRun1.length ; i++);
{
if(daRun1[i] == max || daRun1[i] == min)
{
continue; //<-- **this is where the error is showing (underlined in red in eclipse)**
}
sum += daRun1[i];
}
avg = sum / (daRun1.length-2);
System.out.println("The average score is: " + avg);
我的代码有什么问题?在演示中使用了这个精确的 if 循环,没有任何问题。
最佳答案
问题是 continue
不在 for 循环中。
在这里用分号结束循环:
for (i=0 ; i<daRun1.length ; i++);
删除分号,它应该可以正常工作。
关于Java编译错误-continue不能在循环外使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36694864/