#Occurences of words in a single line of text using hashmaps

1 messages · Page 1 of 1 (latest)

cobalt ivy
#

How can I create a program that uses a hashmap and counts the number of occurrences of words in a single line of text?

coarse ravenBOT
#

<@&987246399047479336> please have a look, thanks.

coarse ravenBOT
#

While you are waiting for getting help, here are some tips to improve your experience:

Code is much easier to read if posted with syntax highlighting and proper formatting.

If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.

Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.

cobalt ivy
#

Here is an example of input and output

#

Rn i can make hashmaps and probably user input

elder kestrel
#

what's the problem? You can read the input and save it to hashmap where key would be "word" and value would be it's frequency so far

#

@cobalt ivy

#

each time you read a new input check if it already exits, if it does then just increase the frequency otherwise initialise it by 1

flat bobcat
#

@cobalt ivy

  1. Create an empty hashmap and Traverse the text line.
    2)while traversing add the new char as a key in the hashmap, if the key already present increment the value by one
    3)Now for example if u check 'a' in the hashmap its value will be no of times the 'a' present in the text line.
cobalt ivy
#

Ty I figured it out