Hackerrank - Java Solution - Pattern Syntax Checker Solution
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