Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- public class Registration {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- int n = Integer.parseInt(sc.nextLine());
- String regex =
- "^(U\\$)(?<username>[A-Z][a-z]{2,})\\1(P@\\$)(?<password>[A-Za-z]{5,}[0-9]+)\\3$";
- Pattern pattern = Pattern.compile(regex);
- int sr = 0;
- while (n>0) {
- String input=sc.nextLine();
- Matcher matcher = pattern.matcher(input);
- if(matcher.matches()){
- String username = matcher.group("username");
- String password = matcher.group("password");
- System.out.println("Registration was successful");
- System.out.println("Username: " + username + ", Password: " + password);
- sr++;
- } else {
- System.out.println("Invalid username or password");
- }
- n--;
- }
- System.out.println("Successful registrations: " + sr);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement