Advertisement
SIRAKOV4444

Untitled

Apr 7th, 2020
328
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 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+)([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. String[] pass = input.split(", ");
  16.  
  17. for (int i = 0; i < pass.length; i++) {
  18. String current = pass[i];
  19. Matcher matcher = pattern.matcher(current);
  20. if (matcher.find()) {
  21. String todo = current;
  22.  
  23. String numbers="";
  24. for(char c: todo.toCharArray()){
  25. if (Character.isDigit(c)) {
  26. numbers=numbers+c;
  27. }
  28. }
  29. //if(numbers.equals("")){
  30. //System.out.print("Product group: 00");
  31. //}else {
  32. System.out.print("Product group: " + numbers);
  33. System.out.println();
  34. //}
  35. } else if (!matcher.find()){
  36. System.out.print("Invalid barcode");
  37. System.out.println();
  38. }
  39. }
  40. nums--;
  41. }
  42. }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement