Check the clock time

Report a typo

For a given string you should check whether it shows time in the correct format. The string should consist of two integers separated by the colon. The first integer should be from 00 to 23 and the second integer should be from 00 to 59.

Note that if only one digit in the integer, it should be padded with a leading zero. That is, strings "5:00" and "05:1" don't show time correctly, but "05:00" and "05:01" do.

Output "YES" if the given string shows time in the correct format, otherwise output "NO".

Sample Input 1:

09:00

Sample Output 1:

YES

Sample Input 2:

23:59

Sample Output 2:

YES

Sample Input 3:

24:00

Sample Output 3:

NO
Write a program in Java 17
import java.util.Scanner;

public class Main {

public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

String regex = "write-your-regex-here";

String time = scanner.nextLine();
System.out.println(time.matches(regex) ? "YES" : "NO");
}
}
___

Create a free account to access the full topic