Java word count program-
In this java program you will learn how to write a java word count program. To develop this program you have to follow below given steps.
- Split the string value using split() method and store it in String array.
- Calculate the size of String array using length method and store it in size Integer variable.
- Create a temporary variable of type int and assign default value 1.
- Create outer for loop and iterate till <size variable.
- Create inner for loop and start index i+1 and iterate till <size variable.
- Check the condition if stringSplit[i].equals(stringSplit[j] condition is true then increment the count variable and set ‘0’ in String array for inner loop current index so that this value will not get counted and get matched with other value .
- Step 6 will get repeated for each index of outer for loop, inner loop will get iterated untill <size.
- Once the inner loop execution completed we are printing index value and its count and setting cout value as default value. (Read Also :program to split integer value in java)
Below is the program for your reference.