Skip to main content

Posts

Showing posts from September, 2014

count occurrences of a word in a statement

public static int countOccurance (String word, String sentence) {          Pattern pattern = Pattern.compile(word ,Pattern.CASE_INSENSITIVE);          Matcher  matcher = pattern.matcher(sentence);          int count = 0; while (matcher.find())     count++;          return count;  }