Advertisement
Guest User

Untitled

a guest
Sep 21st, 2022
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | Software | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class P11_beerTime {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6.  
  7. String time = scanner.nextLine();
  8. String hours = "";
  9. String minutes = "";
  10. String period = "";
  11.  
  12. if (time.length() == 8) {
  13. hours = time.substring(0, 2);
  14. minutes = time.substring(3, 5);
  15. period = time.substring(6, 8);
  16. } else {
  17. hours = time.substring(0, 1);
  18. minutes = time.substring(2, 4);
  19. period = time.substring(5, 7);
  20. }
  21.  
  22. if (period.equals("PM")) {
  23. switch (hours) {
  24. case "1":
  25. case "2":
  26. case "3":
  27. case "4":
  28. case "5":
  29. case "6":
  30. case "7":
  31. case "8":
  32. case "9":
  33. case "10":
  34. case "11":
  35. case "12":
  36. System.out.println("beer time");
  37. break;
  38. default:
  39. System.out.println("non-beer time");
  40. break;
  41. }
  42. } else if (period.equals("AM")) {
  43. switch (hours) {
  44. case "01":
  45. case "02":
  46. System.out.println("beer time");
  47. break;
  48. default:
  49. System.out.println("non-beer time");
  50. break;
  51. }
  52. } else {
  53. System.out.println("Invalid time");
  54. }
  55. }
  56. }
  57.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement