Advertisement
Guest User

Java 1.0

a guest
Apr 4th, 2020
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.83 KB | None | 0 0
  1. package com.company.softuni;
  2.  
  3. import java.util.Scanner;
  4. import java.util.regex.Matcher;
  5. import java.util.regex.Pattern;
  6.  
  7. public class Main3 {
  8.     public static void main(String[] args) {
  9.         Pattern pattern = Pattern.compile("^@#+[A-Z][a-zA-Z0-9]{4,}[A-Z]@#+$");
  10.         Scanner scanner = new Scanner(System.in);
  11.  
  12.         int n = Integer.parseInt(scanner.nextLine());
  13.  
  14.         for (int i = 0; i < n; i++) {
  15.             String line = scanner.nextLine();
  16.             Matcher matcher = pattern.matcher(line);
  17.             if (matcher.matches()) {
  18.                 line = line.replaceAll("\\D+","");
  19.             }
  20.             if (line.isEmpty()) {
  21.                 System.out.println("Product group: 00");
  22.             } else {
  23.                 System.out.println("Product group: " + line);
  24.             }
  25.         }
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement