另一个类将随机数传递给this method(x,y,z)
。我想知道boolean
那确实从我的上一条if()
语句返回了true ,所以我可以对其进行操作。我已经在评论中解释了我的逻辑。
我对此仍然很陌生,因此我的逻辑可能是错误的。
public static String FindDate(int x, int y, int z) {
boolean istrue1 =(x >= 1 && x <= 31);
boolean istrue2 =(y >= 1 && y <= 31);
boolean istrue3 =(z >= 1 && z <= 31);
if(istrue1 ^ istrue2){
if(istrue1^istrue3){
if(istrue2^istrue3){//now knowing that no values are the same, i can find the true value.
if(istrue1||istrue2||istrue3){
// I want to store/use/print/know which bool(istrue) that evaluated to true, so I would know if it is
//x,y,z that went through the algorithm successfully.
}
} else{return "Ambiguous";}
}else{return "Ambiguous";}
}else{return "Ambiguous";}
return "true"; //I would actually end up returning the value that went through the algorithm
}
代替:
if(istrue1||istrue2||istrue3)
将它分解成3个不同的if语句是最容易的。
if(istrue1)
if(istrue2)
if(istrue3)
我没有希望的简单技巧。失落的一天。同样,我对xor(^)运算符所做的陈述也被认为是错误的逻辑。
这将是最简单的:
if(a&&b || a&&c || b&&c)
如果任何组合都为真,那将返回歧义。但是,那不是最初的问题,但我想我也应该提一提。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句