hacker rank java 20th problem solution

20. pattern Syntax checker

import java.util.Scanner;
import java.util.regex.*;

public class Solution
{
public static void main(String[] args){
Scanner in = new Scanner(System.in);
int testCases = Integer.parseInt(in.nextLine());
while(testCases>0){
String syntax = in.nextLine();
       try {
                Pattern.compile(syntax);
                System.out.println("Valid");
            } catch (PatternSyntaxException e) {
                System.out.println("Invalid");
            }
            testCases--;
        }
         
}
}



Compiler Message
Success
Input (stdin)Download
3
([A-Z])(.+)
[AZ[a-z](a-z)
batcatpat(nat
Expected OutputDownload
Valid
Invalid
Invalid

Comments

Popular posts from this blog

Amazon Web Services

Hacker Rank all java and python problem solutions

Testing tools for React Apps