您缺少
return声明。
当编译器查看您的代码时,它会看到
else可能会发生的第三条路径(您未为其编写代码),但未返回任何值。因此
not all pre pathsreturn a value。
对于我建议的修复程序,我
return在循环结束后加上了a 。另一个明显的地方-向中添加一个
else具有
return值的
if-else-if-会破坏
for循环。
public static bool isTwenty(int num){ for(int j = 1; j <= 20; j++) { if(num % j != 0) { return false; } else if(num % j == 0 && num == 20) { return true; } } return false; //This is your missing statement}


