Guest User

FancyBarcodes

a guest
Apr 8th, 2020
278
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Scanner;
  2. import java.util.regex.Matcher;
  3. import java.util.regex.Pattern;
  4.  
  5. public class _02_FancyBarcodes {
  6.     public static void main(String[] args) {
  7.         Scanner console = new Scanner(System.in);
  8.         int steps = Integer.parseInt(console.nextLine());
  9.  
  10.         while (steps-- > 0) {
  11.             Pattern pattern = Pattern.compile("^(@#+)([A-Z][A-Za-z0-9]{4,}[A-Z])(@#+)$");
  12.             Matcher matcher = pattern.matcher(console.nextLine());
  13.             if (matcher.find()) {
  14.                 matcher = Pattern.compile("\\d").matcher(matcher.group());
  15.                 System.out.print("Product group: ");
  16.                 if (matcher.find()){
  17.                     System.out.print(matcher.group());
  18.                     while(matcher.find())
  19.                         System.out.print(matcher.group());
  20.                 }
  21.                 else
  22.                     System.out.print("00");
  23.                 System.out.println();
  24.             } else
  25.                 System.out.println("Invalid barcode");
  26.         }
  27.     }
  28. }
RAW Paste Data