MeGaM1nd

Untitled

Apr 4th, 2020
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.util.regex.Matcher;
  3. import java.util.regex.Pattern;
  4.  
  5. class fancy {
  6.  
  7. public static void main(String[] args) {
  8.  
  9. Scanner scanner = new Scanner(System.in);
  10.  
  11. int number = Integer.parseInt(scanner.nextLine());
  12. String regex = "@#+([A-Za-z0-9]+)+@#+";
  13.  
  14. String regexTwo = "(\\d+)";
  15. Pattern pattern = Pattern.compile(regex);
  16. Pattern patternTwo = Pattern.compile(regexTwo);
  17.  
  18. for (int i = 0; i < number; i++) {
  19.  
  20. String message = scanner.nextLine();
  21.  
  22. Matcher matcher = pattern.matcher(message);
  23. Matcher matcherTwo = patternTwo.matcher(message);
  24.  
  25. if (matcher.find()) {
  26. String barcode = matcher.group(0);
  27.  
  28. if (matcherTwo.find()) {
  29. String text = matcherTwo.group(0);
  30.  
  31. while (matcherTwo.find()) {
  32. text += matcherTwo.group(0);
  33. }
  34. System.out.println("Product group: " + text);
  35. } else {
  36. System.out.println("Product group: 00");
  37. }
  38.  
  39.  
  40. } else {
  41. System.out.println("Invalid barcode");
  42. }
  43.  
  44. }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment