Hello, I am new here and I am learning to code. I am doing an exercise in which I need to find the frequency of words in a given string and put them in a LinkedList. I feel as though I am fairly close but no cigar. Any help would be appreciated.
Have you ever used Maps? Counting the frequency of something is also known as computing a histogram. This is usually done with a Map.
Where the key is the word and the value is an integer which is a count of the number of times the word appears. You have to iterate through all your words, and for each word, if it is not in the Map then add it with a count of one, if it is in the Map increment the count.
It keeps me from spending any more time with this OP on the other forum. Once a question is posted here the locals will take care of doing the design and debugging for the OP and help him get a working program without him having to spend too much time working through details.
Eric Dolland wrote:Hello, I am new here and I am learning to code. I am doing an exercise in which I need to find the frequency of words in a given string and put them in a LinkedList.
Hi Eric, welcome to the Ranch!
One thing about programming, if you try to write code and you don't have a clear description of what the code is supposed to do, then you're going to flounder. That's not just beginners, that's everyone.
So: what is your code supposed to do? I can see that you're supposed to extract words from a string. Then you're supposed to find the frequency of those words; I'm going to assume that's the frequency of the words in that set of words. And then I'm stuck. You're supposed to put "them" in a LinkedList. What's "them"? The words, or the frequencies?
Hopefully you're working from an assignment which states the requirements more clearly. Could you tell us what the requirements are, then?
Willie Smits can speak 40 languages. This tiny ad can speak only one: