top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Java: Implement a code to count the occurrences of each word in input file and write the word with count in output file?

+3 votes
1,080 views

Implement a code that counts the occurrences of each word in an input file and write the word along with corresponding count in an output file sorted by the words alphabetically.

Sample Input

Gaurav is  a Good Boy
Sita is a Good Girl
Tommy is  a Good Dog
Ram is a Good person

Sample Output

D:\>Java FileWordCount inputFile.txt outputFile.txt
    Boy : 1
    Dog : 1
    Gaurav : 1
    Girl : 1
    Good : 4
    Ram : 1
    Sita : 1
    Tommy : 1
    a : 4
    is : 4
    person : 1
posted Apr 22, 2017 by Azhar Keer

Looking for an answer?  Promote on:
Facebook Share Button Twitter Share Button LinkedIn Share Button

Similar Questions
0 votes

Given a sentence and a word, remove all occurrences of the word in the sentence.

For example, removing “is” from the sentence “This is a boy.” becomes “Th a boy.”

+4 votes

Design an algorithm to accept a string from the user. Count and print the number of times each character occurs in the given string. Example –
input string = "malayalam"
Output must be –
m – 2
a – 4
l – 2
y - 1

0 votes

Write a C code for the logic -
input: string, strong
output: strng

...