I have to perform certain operation when the condition doesn't matches, or if i have certain condition i don't have to do anything, if not i have to perform certain operation.What's the most efficient way to re-write the below code? So when text = "ABC" AND flag = 0 OR flag = 5 We don't do anything, but except than that i need a block of code that has to be executed.
I tried negating the condition but doesn't works.
if (!text.equals("ABC") && (flag != 0 || flag != 5))
public class Main {
public static void main(String args[]){
test3if(5,"ABC");
}
public static void test3if(int flag, String stopTypeCd) {
if (text.equals("ABC") && (flag == 0 || flag == 5)) {
System.out.println("Do nothing");
}
else {
System.out.println("Do Something");
}
}
Aucun commentaire:
Enregistrer un commentaire