Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- public class test {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int n = Integer.parseInt(scanner.nextLine());
- for (int i = 0; i < n; i++) {
- String input = scanner.nextLine();
- String regex = "(?<symbol>[@])[#]+(?<words>[A-Z][A-Za-z0-9A-Z]{4,}[A-Z])(\\1)[#]+";
- Pattern pattern = Pattern.compile(regex);
- Matcher matcher = pattern.matcher(input);
- if (matcher.find()) {
- boolean isInvalid = false;
- String barcodeProduct = "";
- String code = matcher.group("words");
- for (int j = 0; j < code.length(); j++) {
- char barcodes = code.charAt(j);
- if (Character.isDigit(barcodes)) {
- barcodeProduct += barcodes;
- }
- }
- if (!barcodeProduct.equals("")) {
- System.out.printf("Product group: %s%n", barcodeProduct);
- } else {
- System.out.println("Product group: 00");
- }
- }else {
- System.out.println("Invalid barcode");
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment