Program to count number of occurrences of word in a string|Selenium Tutorial

While attending interviews you should be ready with some sample program which they might ask because they want to see how you are applying logics for a specific program.

Today I am covering very basic program which simply check count  number of occurrences of a word in a string.

Program to count  number of occurrences of word in a string

The scenario is- You will be getting a specific String i.e Selenium Webdriver Online Tutorial and you need to search for e character and number of occurrence as well.

Approach-

1- First accept one String from user and Store in String variable.

2- Then accept char which you want to search in String

3- Take counter variable which will increment if match found

4- Finally print the counter value.

 

JAVA Program to count  number of occurrences of word in a string

 

For above program, there can be many solutions, I have posted which I use generally if you have any other solution then please let me know so that I can add in this post.

Guys be ready with such type of questions and I will try to post as much as possible.If you are looking for any specific program the comment below.

 

8 Comments

  1. Tahir
  2. Aamer Hussain
  3. surabhi
  4. dinesh

Leave a Reply