Advertisement
sunfresh

Beer time

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