Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package FinalExam.O5;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Scanner;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- public class O2EmojiDetector {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String input = scanner.nextLine();
- int sum = 1;
- int counter = 0;
- Matcher matcher = Pattern.compile("(?<numbers>\\d)").matcher(input);
- while (matcher.find()) {
- int number = Integer.parseInt(matcher.group("numbers"));
- sum = sum * number;
- }
- Matcher matcher2 = Pattern.compile("(?<name>([*]{2})[A-Z][a-z]{2,}([*]{2})|([:]{2})[A-Z][a-z]{2,}([:]{2}))")
- .matcher(input);
- List<String> collList = new ArrayList<>();
- while (matcher2.find()) {
- int sumChar = 0;
- String name = matcher2.group("name");
- counter++;
- for (int i = 2; i < name.length() - 2; i++) {
- char a = name.charAt(i);
- sumChar += a;
- }
- if (sumChar > sum) {
- collList.add(name);
- }
- }
- System.out.println("Cool threshold: " + sum);
- System.out.println(counter + " emojis found in the text. The cool ones are:");
- for (String s : collList) {
- System.out.println(s);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment