Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class BeerTimeFor {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String time = scanner.nextLine();
- int a = time.length();
- String substringTime = time.substring(a - 2);
- String substring2 = time.substring(0, 2);
- String substring3 = time.substring(0, 1);
- String minutes1 = time.substring(a - 5, a - 3);
- int hours8 = 0;
- int hours7 = 0;
- int minutes = 0;
- if (substringTime.equals("AM")) {
- minutes = Integer.parseInt(minutes1);
- if (minutes > 59) {
- System.out.println("invalid time");
- } else if (a == 8) {
- hours8 = Integer.parseInt(substring2);
- if (hours8 >= 1 && hours8 < 3 || hours8 == 12) {
- System.out.println("beer time");
- } else if (hours8 >= 3 && hours8 < 6 || hours8 >= 10 && hours8 <= 11) {
- System.out.println("non-beer time");
- } else {
- System.out.println("invalid time");
- }
- } else if (a == 7) {
- hours7 = Integer.parseInt(substring3);
- if (hours7 >= 6 && hours7 <= 9) {
- System.out.println("non-beer time");
- } else {
- System.out.println("invalid time");
- }
- }
- } else if (substringTime.equals("PM")) {
- minutes = Integer.parseInt(minutes1);
- if (minutes > 59) {
- System.out.println("invalid time");
- }
- else if (a == 8) {
- hours8 = Integer.parseInt(substring2);
- if (hours8 >= 10 && hours8 <= 11) {
- System.out.println("beer time");
- } else if (hours8 == 12) {
- System.out.println("non-beer time");
- } else {
- System.out.println("invalid time");
- }
- } else if (a == 7) {
- hours7 = Integer.parseInt(substring3);
- if (hours7 >= 1 && hours7 <= 9) {
- System.out.println("beer time");
- } else {
- System.out.println("invalid time");
- }
- } else {
- System.out.println("invalid time");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement