- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAgeCheck.java
More file actions
Latest commit
19 lines (14 loc) · 839 Bytes
/
Copy pathAgeCheck.java
File metadata and controls
19 lines (14 loc) · 839 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
importjava.util.Scanner; // Import the Scanner n
publicclassAgeCheck {
publicstaticvoidmain(String[] args) {
Scannerscanner = newScanner(System.in); // New Scanner
System.out.println("Are you 18 or over? (yes/no)"); // Ask the user if they are 18 or over
Stringstr1 = scanner.nextLine(); // Read in the user input as a string and store it in a variable called str1
if (str1.equalsIgnoreCase("yes") || str1.equalsIgnoreCase("y")) {
System.out.println("Welcome sir/madam"); // Displayes "Welcome sir/madam"
} elseif (str1.equalsIgnoreCase("no") || str1.equalsIgnoreCase("n")) {
System.out.println("You are a minor, entry not permitted"); // Displays "You are a minor, entry not permitted"
scanner.close(); // close the Scanner
}
}
}