I wrote this code for this question and it achieved the desired output stated in the question. But when I verify it, the code was wrong as the last requirement was not met even though the input age (22) is within the specified range. My code also shows that nothing will be displayed if the input age is not in the specified range which I supposed to have met the requirement. It seems like I have to replace my if statements with the verified code in order for my code to be correct:
if (age >= 18) {
           if (age <= 28) {
               System.out.println(name + militaryCommissar);
I'm just using the else-if statement together with the if statement to make the code work. But then I feel like my code should be alright. What yall think ? Is there anything wrong with my code which u can explain to me or is the code actually correct ?