在java中实现54 if else条件的最佳方法是什么 [英] What is the best way to implement 54 if else conditions in java
问题描述
我需要检查所有54种可能性检查它的最佳方法是否正在使用其他条件
我尝试了什么:
例如:
< code>
//前3个条件的a,b,c值为
if(a = a&& a = a&& a = a&& a = 1)
{
// logic
}
else if(a = a&& a = a&& a = a&& a = 0)
{
// logic
}
else if(a = a&& a = a&& a = b&& a = 1)
{
//逻辑
}
< / code>
一种可能性,再次依赖你计划的是将它重组为嵌套条件
如果(a == a1) {
if (b == b2){
if (c == c3){
}
其他 {
}
}
else {
}
}
else {
// 条件测试的内容与上述相同
}开以上优点是你只进行一次测试。
另一个优点是可以通过在巢中插入额外的块来进行修改。
如果您正在测试多个值,请认识一个块可能包含多个其他块,但是您应该考虑使用该开关进行该特定测试。
此解决方案基本上是通用的:
您的目标应该是尝试每次只执行一次测试,然后使用if()或switch来构建每个结果的路径并使其灵活()/根据条件将变量设置为1 - 54,然后有一个switch语句,根据该变量的值执行逻辑。
i need to check all 54 possibilities what is the best way to check it present i am using if else conditions
What I have tried:
ex: <code> //first 3 conditions have a,b,c values if(a=a && a=a && a=a && a=1) { //logic } else if(a=a && a=a && a=a && a=0) { //logic } else if(a=a && a=a && a=b && a=1) { //logic } </code>解决方案One possibility, again dependent upon what you're planning is to reorganize it to nested conditionals
if(a==a1) { if(b==b2) { if(c==c3) { } else{ } } else{ } } else { // Same content as above for the conditional tests }One advantage of the above is you only do each test once.
Another advantage is modifications can made by inserting additional blocks in the nest.
Realize that a block may contain more than one else if you have more than one value you are testing for, but then you ought to consider using a switch for that particular test.
This solution is essentially generic:
Your goals should be a combination of trying to do each test only once and thus building a path to each result and making it flexible, using if() or switch() as appropriate.
Set a variable to 1 - 54 based on the conditions and then have a switch statement that executes the logic based on the value of that variable.
这篇关于在java中实现54 if else条件的最佳方法是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!