English 中文(简体)
如果结果相同,我如何将其他办法转换成“和”。
原标题:How do I convert if else to && || in if the result is the same

如果每个条件的产出在这些情况下相同,则如何替换;和

在完成产出之前,要满足多种不同条件,每个产出不变。

请注意,条件和产出只是持有人,因为这主要是一个假装的问题。

案例1:

if(condition 1){
    if(condition 2){
        if(condition 3){
            if(condition 4){
                if(condition 5){
                    return(1);
                }
                if(condition 6){
                    if(condition 7){
                        return(1);
                    } 
                }
            }else{
                if(condition 10){
                     return(1);
                }
            }
        }
    }
}

案例2:

if(condition 1){
    if(condition 2){
        if(condition 3){
            if(condition 4){
                if(condition 6){
                    if(condition 8){
                         return(2);
                        }   
                }else{
                    if(condition 9){
                        return(2);
                    }
                }
            }
        }else{
            if(condition 11){
                  return(2);
            }
        }
    }else{
        if(condition 12){
            return(2);
        }
    }
}else if(condition 13){
    if(condition 14){
        return(2);
    }
}

两种情况都可以通过使用和复制两种方式将这两种情况都降至1例;如果“prop”和“prop”两种情况都符合条件,因为尽管有多种条件,但这两种情况都只有一个结果。

the solution I am looking for would look something like: 案例1:

if((condition1 && condition 2) || (condition 3)){
   return (1);
}

案例2:

if((condition1 && condition 2) || (condition 4)){
   return (2);
}
问题回答

你们是否想像这样的东西?

if(condition 1 && condition 2 && condition 3 && condition 4){
if(condition 5){ return 1}
if(condition 6 && condition 7){ return 1}
...
}

它肯定会帮助澄清一点点。

如果所有条件都产生同样的结果,那么你就能够保证:

案件:

if ( (condition1 && condition2 && condition3) && (condition4 && condition5) || (condition4 && condition6 && condition7) || (condition10) ) return(1);

案件:

if ( (condition1 && ((condition2 && ((condition3 && condition4 && ((condition6 && condition8) || condition9)) || condition11)) || condition12)) || (condition13 && condition14)) return(2);




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签