title: A java program to find out the frequrncy of a word using Scanner class
body: <p>Can any one tell me that how to use Scanner Class of Java to find the frequency of a word in a sentence.</p>
  
  <p>I am confused as to enter a line in java i have to use nextInt() function but to compare need it to convert in char so how to do so.</p>
  
  <p>For example:-</p>
  
  <p>I enter on terminal window(Giving Input)</p>
  
  <p>This is my cat.</p>
  
  <p>Now i have to find the FREGUENCY of word "this" in the above sentence. Please can you give me some idea.REMEMBER THE RESTRICTION IMPOSED ON IT IS I HAVE TO USE ONLY SCANNER CLASS OF JAVA LIBRARY</p>
  
  <p>PROGRAMME USING STREAM READER IS AS FOLLOWS-</p>
  
  <pre><code>import java.io.*;
  
  class FrequencyCount
  {
  
      public static void main(String args[]) throws IOException
      {
          BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
  
          System.out.println("Enter the String: ");
          String s=br.readLine();
          System.out.println("Enter substring: ");    
          String sub=br.readLine();
  
          int ind,count=0;
          for(int i=0; i+sub.length()&lt;=s.length(); i++)
          //i+sub.length() is used to reduce comparisions  
          {
              ind=s.indexOf(sub,i);
              if(ind&gt;=0)
              {
                  count++;
                  i=ind;
                  ind=-1;
              }
          }
          System.out.println("Occurence of '"+sub+"' in String is "+count);
      }
  }
  </code></pre>