I am looking for any better way to handle this if condition to print values. I am looking to print if both are true i want to print both messages and if not only one message.
boolean codeExists = false, nameExists = false;
for (condition) {
if(condition){
codeExists = true;
}
if(condition)) {
nameExists = true;
}
}
if(codeExists && nameExists) {
System.out.println("CodeExists");
System.out.println("NameExists");
}
else if(codeExists) {
System.out.println("CodeExists");
}
else if(nameExists) {
System.out.println("NameExists");
}
else {
System.out.println("Another statements to print");
}
do we have any better approach to print the below messages.
Aucun commentaire:
Enregistrer un commentaire