Problem solving with programming: How to find the frequecy of a word in a given sentence
Given some text and a word. How do we find the frequency of the word?In this post we will see a Java program which finds it with just a few lines of code using regular expression matching.
Java provides utilities for matching the regular expressions using java.util.regex package. In our program we utilize two of them namely Pattern, and Matcher. These are the fundamental classes in this package.
In the following code reader is an object of class Scanner which is used for reading the input from the keyboard. The Pattern class does not have a public constructor, we have to create an object of that class using the compile() method by passing the pattern. Similarly the Matcher class also does not have a public constructor, and it's object should be returned by matcher() method of the Pattern object.
Read full article from Problem solving with programming: How to find the frequecy of a word in a given sentence
No comments:
Post a Comment