问题描述
我如何使这项工作?它说,我需要添加一个return语句,但我有一个。
公共布尔clockFactCheck(INT A,INT B){
的for(int i = 0; I< = 276;我++){
对于(INT H = 0; H< = 55; H ++){
如果(一个== I + 186放大器;和b == H + 133){
返回true;
}其他{
返回false;
}
}
}
}
提供可能达不到回报之一的code
S表示任何输入 A,b
这就是编译器抱怨。
其实你的情况的if-else
将与第一个迭代达到了 - 可惜东西编译器无法推断。因此,这是不言而喻的保存方式发出此错误。
的注释:的。因此,在你的循环似乎没有太大的意义,因为它不会重复,不过在第一次迭代内停止我== 0
和 ^ h == 0
。难道你的意思是code类似的东西?
How do I make this work? It says that I need to add a return statement but I have one.
public boolean clockFactCheck(int a, int b){
for (int i = 0; i <= 276; i++){
for (int h = 0; h <= 55; h++){
if (a == i + 186 && b == h + 133){
return true;
} else {
return false;
}
}
}
}
The code provided may not reach one of the return
s for any input a,b
and that's what the compiler is complaining about.
Actually in your case the if-else
will be reached with the very first iteration - unfortunately something which the compiler cannot deduce. Therefore, it goes the save way and issues this error.
Comment: Therefore, in your loop seems not to make much sense since it will not iterate at all but stop within the first iteration i==0
and h==0
. Did you meant to code something like that?
这篇关于嵌套for循环的if-else块 - 编译器要求我需要一个return语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!