I am trying to check validity of n regex and it works good but it does not passes all the test cases . I am not able to find out why is this happening.
import java.util.Scanner;
import java.util.regex.Pattern;
public class Solution
{
public static void main(String[] v)
{
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
sc.next();
int j=0;
String[] patt=new String[n];
while(j<n)
{
patt[j]=sc.nextLine();
j++;
}
for(int i=0;i<n;i++)
{
try
{
Pattern.compile(patt[i]);
System.out.println("Valid");
//System.out.println(patt.length);
}
catch(Exception e)
{
System.out.println("Invalid");
}
}
}
}
Aucun commentaire:
Enregistrer un commentaire