Valid
PAN format
The following is the solution to the Hacker Rank problem "Valid PAN format". For
other Hacker Rank problem solutions visit my Hacker Rank Solutions Page.
/**
* @author Arun.G
*
*/
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
public static void main(String[]
args) {
/* Enter your code here. Read input from
STDIN. Print output to STDOUT. Your class should be named Solution. */
Scanner sc = new Scanner(System.in);
int numberOfPans =
sc.nextInt();
while(numberOfPans--
>=0)
{
String pan = sc.nextLine();
if(!pan.equals(""))
{
Pattern panPattern = Pattern.compile("\\b[A-Z]{5}\\d{4}[A-Z]{1}");
Matcher m =
panPattern.matcher(pan);
if(m.find())
System.out.println("YES");
else
System.out.println("NO");
}
}
}
}
|
No comments:
Post a Comment