Advertisement
CR7CR7

BeerTime

Sep 23rd, 2022
741
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.86 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Homework11 {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         String input = scanner.nextLine();
  7.         String time = "";
  8.         int hour = 0;
  9.         int minute = 0;
  10.  
  11.         if (input.length() == 7){
  12.             time = input.substring(input.length()-2);
  13.             hour = Integer.parseInt(input.substring(0, 1));
  14.             minute = Integer.parseInt(input.substring(2, 4));
  15.         } else if (input.length() == 8) {
  16.             time = input.substring(input.length()-2);
  17.             hour = Integer.parseInt(input.substring(0, 2));
  18.             minute = Integer.parseInt(input.substring(3, 5));
  19.  
  20.         }
  21.         if ("PM".equals(time)) {
  22.             switch (hour) {
  23.                 case 0:
  24.                     System.out.println("non-beer time");
  25.                     break;
  26.                 case 1:
  27.                 case 2:
  28.                 case 3:
  29.                 case 4:
  30.                 case 5:
  31.                 case 6:
  32.                 case 7:
  33.                 case 8:
  34.                 case 9:
  35.                 case 10:
  36.                 case 11:
  37.                 case 12:
  38.                     System.out.println("beer time");
  39.                     break;
  40.             }
  41.         } else if ("AM".equals(time)) {
  42.             switch (hour) {
  43.                 case 0:
  44.                 case 1:
  45.                 case 2:
  46.                     System.out.println("beer time");
  47.                     break;
  48.                 case 3:
  49.                 case 4:
  50.                 case 5:
  51.                 case 6:
  52.                 case 7:
  53.                 case 8:
  54.                 case 9:
  55.                 case 10:
  56.                 case 11:
  57.                 case 12:
  58.                     System.out.println("non-beer time");
  59.                     break;
  60.             }
  61.         }
  62.  
  63.  
  64.     }
  65. }
  66.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement