Pattern Syntax Checker

  • + 0 comments

    better approach rather than consuming empty line using nextLine()

    public static void main(String[] args){
    		Scanner in = new Scanner(System.in);
    		int testCases = Integer.parseInt(in.nextLine());
    		while(testCases>0 && in.hasNext()){
    			String pattern = in.nextLine();
              	//Write your code
                try{
                Pattern pattern2 = Pattern.compile(pattern);
                System.out.println("Valid");
                }catch(Exception ex){
                    System.out.println("Invalid");
                }
    		}
            in.close();
    	}