Pattern Syntax Checker

윤지현·2025년 3월 26일
0

HackerRank[Java]

목록 보기
26/57
  • 문제
  • 정답
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 pattern = in.nextLine();
          	try {
                Pattern.compile(pattern);
                System.out.println("Valid");
            } catch(PatternSyntaxException e) {
                System.out.println("Invalid");
            }
            testCases--;
		}
        
        in.close();
	}
}
  • 결과
profile
첫 시작

0개의 댓글