Advertisement
SIRAKOV4444

Untitled

Apr 8th, 2020
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 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 lqlq {
  6. public static void main(String[] args) {
  7. Scanner scanner = new Scanner(System.in);
  8.  
  9. String regex = "^(@#+)([A-Z])(\\w{5,})([A-Z])(\\1)$";
  10. int nums = Integer.parseInt(scanner.nextLine());
  11. Pattern pattern = Pattern.compile(regex);
  12.  
  13. while (nums > 0) {
  14. String input = scanner.nextLine();
  15.  
  16. Matcher matcher = pattern.matcher(input);
  17. if (matcher.matches()) {
  18. String numbers = "";
  19. for (char c : input.toCharArray()) {
  20. if (Character.isDigit(c)) {
  21. numbers += c;
  22. }
  23. }
  24. if (!numbers.equals("")) {
  25. System.out.print("Product group: " + numbers);
  26. System.out.println();
  27. } else {
  28. System.out.print("Product group: 00");
  29. System.out.println();
  30. }
  31. } else {
  32. System.out.print("Invalid barcode");
  33. System.out.println();
  34. }
  35. nums--;
  36. }
  37. }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement