Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class exam {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String code = "";
- int n = Integer.parseInt(scanner.nextLine());
- for(int i = 0 ;i < n; i++) {
- code ="";
- String barcode = scanner.nextLine();
- char firstSymbol = barcode.charAt(0);
- if(firstSymbol != '@') {
- System.out.println("Invalid barcode");
- continue;
- }
- char secondSymbol = barcode.charAt(1);
- if(secondSymbol != '#') {
- System.out.println("Invalid barcode");
- continue;
- }
- String newWord = barcode.replace("@", "");
- newWord = newWord.replace("#", "");
- newWord = newWord.replace(" ", "");
- char firstLetter = newWord.charAt(0);
- if(Character.isLowerCase(firstLetter)) {
- System.out.println("Invalid barcode");
- continue;
- }
- boolean isStupid = true;
- for(int j= 0; j < newWord.length(); j++) {
- if(!Character.isLetterOrDigit((newWord.charAt(j)))) {
- System.out.println("Invalid barcode");
- isStupid = false;
- }
- }
- if(isStupid == false) {
- continue;
- }
- char lastLetter = newWord.charAt(newWord.length() - 1);
- if(Character.isLowerCase(lastLetter)) {
- System.out.println("Invalid barcode");
- continue;
- }
- for(int k = 0; k < newWord.length(); k++) {
- if(Character.isDigit(newWord.charAt(k))) {
- code += newWord.charAt(k);
- }
- }
- if(code.isEmpty()) {
- code = "00";
- }
- System.out.printf("Product group: %s%n", code);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement