In my project, there is a logic similar to the following code, and there will be many types, but this is too messy to write, I want to ask if there is any more elegant way.
int a = 3,b = 5;
int type = 2;
if (type == 1) {
if (a > 1) {
System.out.println("a > 1");
} else if (b > 3) {
System.out.println("b > 3");
}
}
if (type == 2) {
if (b > 3) {
System.out.println("b > 3");
} else if (a > 1) {
System.out.println("a > 1");
}
}
Aucun commentaire:
Enregistrer un commentaire