Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- class fancy {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int number = Integer.parseInt(scanner.nextLine());
- String regex = "@#+([A-Za-z0-9]+)+@#+";
- String regexTwo = "(\\d+)";
- Pattern pattern = Pattern.compile(regex);
- Pattern patternTwo = Pattern.compile(regexTwo);
- for (int i = 0; i < number; i++) {
- String message = scanner.nextLine();
- Matcher matcher = pattern.matcher(message);
- Matcher matcherTwo = patternTwo.matcher(message);
- if (matcher.find()) {
- String barcode = matcher.group(0);
- if (matcherTwo.find()) {
- String text = matcherTwo.group(0);
- while (matcherTwo.find()) {
- text += matcherTwo.group(0);
- }
- System.out.println("Product group: " + text);
- } else {
- System.out.println("Product group: 00");
- }
- } else {
- System.out.println("Invalid barcode");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment