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;
- public class _06_CountSpecifiedWord {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- String input = sc.nextLine().toLowerCase();
- String keyWord = sc.nextLine();
- String regEx = "\\b" + keyWord + "\\b";
- Pattern textPattern = Pattern.compile(regEx);
- Matcher matcher = textPattern.matcher(input);
- int counter = 0;
- while(matcher.find()){
- counter++;
- }
- System.out.println(counter);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment