Advertisement
SIRAKOV4444

Untitled

Apr 7th, 2020
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.util.regex.Matcher;
  3. import java.util.regex.Pattern;
  4.  
  5. public class Registration {
  6. public static void main(String[] args) {
  7. Scanner sc = new Scanner(System.in);
  8.  
  9. int n = Integer.parseInt(sc.nextLine());
  10. String regex =
  11. "^(U\\$)(?<username>[A-Z][a-z]{2,})\\1(P@\\$)(?<password>[A-Za-z]{5,}[0-9]+)\\3$";
  12. Pattern pattern = Pattern.compile(regex);
  13. int sr = 0;
  14. while (n>0) {
  15. String input=sc.nextLine();
  16. Matcher matcher = pattern.matcher(input);
  17. if(matcher.matches()){
  18. String username = matcher.group("username");
  19. String password = matcher.group("password");
  20. System.out.println("Registration was successful");
  21. System.out.println("Username: " + username + ", Password: " + password);
  22. sr++;
  23. } else {
  24. System.out.println("Invalid username or password");
  25. }
  26. n--;
  27. }
  28. System.out.println("Successful registrations: " + sr);
  29. }
  30.  
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement