lundi 27 mai 2019

How to code a if-statement for asking drinking age

I'm writing a code to determine if someone can enter a club and whether or not they can drink at the club. I was wondering if I am doing this right, and if there is a better way to write the code. Thanks.

public class SoloJava {

    public static void main(String[] agrs) {
        int age = 17;
        if (age >= 18) {
            System.out.println("You can enter");
        }
        if (age < 18) {
            System.out.println("You can not enter");
        }
        if (age >= 21) {
            System.out.println("You can drink");
        } else if (age <= 21) {
            System.out.println("You can not drink");
        }
    }
}

Aucun commentaire:

Enregistrer un commentaire