by Dinesh Thakur Category: Control Structures

Algorithm for Number of Times a Word has Been Mentioned :

step 1: read String w
step 2: read String w1
step 3: set len=w1.length()
step 4: set result=0

step 5: If len> 0 then executes following steps else goto step-10
step 6: Set start =w.indexof(w1, start+len)
step 7: repeat through step-9 while(start 1= -1)
step 8: result= result+ 1
step 9: start = w. indexof(w1, start+ len)
step 10: print result
step 11: Exit

Here is the Java Example for - Number of Times a Word has Been

import java.util.*;

public class WordCount
                        public static void main(String args[])
                       System.out.print("Please Enter the Sentence : ");
                       Scanner Word=new Scanner(;
                       String Count=Word.nextLine();
                       System.out.print("Please Enter the Word : ");
                       String wl=Word.nextLine();
                       int len=wl.length();
                       int CountWord =0;
                       if(len> 0)
                              int start = Count.indexOf(wl);


 Number of Times a Word has Been Mentioned

About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.

Search Content

Popular Article