Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class P11_beerTime {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String time = scanner.nextLine();
- String hours = "";
- String minutes = "";
- String period = "";
- if (time.length() == 8) {
- hours = time.substring(0, 2);
- minutes = time.substring(3, 5);
- period = time.substring(6, 8);
- } else {
- hours = time.substring(0, 1);
- minutes = time.substring(2, 4);
- period = time.substring(5, 7);
- }
- if (period.equals("PM")) {
- switch (hours) {
- case "1":
- case "2":
- case "3":
- case "4":
- case "5":
- case "6":
- case "7":
- case "8":
- case "9":
- case "10":
- case "11":
- case "12":
- System.out.println("beer time");
- break;
- default:
- System.out.println("non-beer time");
- break;
- }
- } else if (period.equals("AM")) {
- switch (hours) {
- case "01":
- case "02":
- System.out.println("beer time");
- break;
- default:
- System.out.println("non-beer time");
- break;
- }
- } else {
- System.out.println("Invalid time");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement