noob here, trying to help. From what I understand there are 3 possibilities.
- Can’t enter (younger than 18 years old)
- May enter but can’t get a drink (younger than 21 but still over 18)
- Can enter and have a drink (over 21 years old)
Therefore I think that it would be best to minimize the number of if statements.
public static void main(String[] args) {
int age = 20;
if (age<18){
System.out.println("You cannot enter");
}
else if(age>=18 && age<=21){ //checks if his/her age is between 18 and 21
System.out.println("You may enter but you cannot drink");
}
else{
System.out.println("You may enter and have a drink");
}
}
solved How to code a if-statement for asking drinking age