Guest User

Untitled

a guest
May 24th, 2014
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.55 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.util.regex.Matcher;
  3. import java.util.regex.Pattern;
  4.  
  5.  
  6. public class _06_CountSpecifiedWord {
  7.  
  8.     public static void main(String[] args) {
  9.  
  10.         Scanner sc = new Scanner(System.in);
  11.        
  12.         String input = sc.nextLine().toLowerCase();
  13.         String keyWord = sc.nextLine();
  14.        
  15.         String regEx = "\\b" + keyWord + "\\b";
  16.         Pattern textPattern = Pattern.compile(regEx);
  17.         Matcher matcher = textPattern.matcher(input);
  18.         int counter = 0;
  19.  
  20.         while(matcher.find()){
  21.             counter++;
  22.         }
  23.         System.out.println(counter);
  24.     }
  25.  
  26. }
Advertisement
Add Comment
Please, Sign In to add comment