我怎样才能更好地实现这个逻辑

Sam*_*Sam 1 java if-statement conditional-statements

我试图实现这个逻辑,我只是​​想知道是否有更好的方法?

if(condition1) {
    do1();
}
else if(condition2) {//especially here that I have to check condition3 here and also in the last else if
    do2();
    if(condition3) {
        do3();
    }
}
else if(condition3) {
    do3();
}
Run Code Online (Sandbox Code Playgroud)

Pra*_*ker 5

试试这个

if(condition1) 
{
   do1();
}
else
{
   if(condition2) 
   {
      do2();
   }
   if(condition3) 
   {
     do3();
   }
}
Run Code Online (Sandbox Code Playgroud)