Hackerrank - Java Solution - Pattern Syntax Checker Solution - Online Judge Solution

Latest

It is a free Online judges problems solution list. Here you can find UVA online Judge Solution, URI Online Judge Solution, Code Marshal Online Judge Solution, Spoz Online Judge Problems Solution

Tuesday, December 12, 2017

Hackerrank - Java Solution - Pattern Syntax Checker Solution

Hackerrank - Java Solution - Pattern Syntax Checker Solution

HackerRank Problem Solution

Problem Name -  Pattern Syntax Checker
Problem Link -   Pattern Syntax Checker 
Level - String
Point - 20

Java Code
import java.util.Scanner;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;

public class Solution {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int testCases = scan.nextInt();
        scan.nextLine();
        
        // If a PatternSyntaxException is not thrown by Pattern.compile, the regular expresion is valid
        while (testCases-- > 0) {
           String pattern = scan.nextLine();
           try {
               Pattern.compile(pattern);
               System.out.println("Valid");
           } catch (PatternSyntaxException exception) {
               System.out.println("Invalid");
           }
        }
        scan.close();
    }
}



Tags: HackerRank Online Judge Solution, HackerRank OJ Solution list, HackerRank Problems Solution, HackerRank solver, HackerRank all problem solution list, HackerRank solution in java, Hackerrank Java Solution, Hackerrank - Java Solution - Pattern Syntax Checker Solution ,Hackerrank Online Judge Solution, Hackerrank - Java Solutions,

No comments:

Post a Comment