Can you show the input and output of the program and describe what is wrong with the output and say what the output should be?
It should count the same word once instead of twice.
How are you keeping track of what words have been counted so that you don't count them again?
NormR1
Posting Expert
6,677 posts since Jun 2010
Reputation Points: 1,138
Solved Threads: 656
The code is very confusing. You should better try to use a while() instead of 'if'.
Here's an example:
while(paragraph[i]!=' ')i++;...
Try to enter this code in yours. you will need another while for reading all spaces if there is more than one together.
teo236
Junior Poster in Training
73 posts since Jul 2011
Reputation Points: 20
Solved Threads: 10
you could use a vector that stores strings and then compare the current word to the words in the vector and if the word already appears then you don't increase the count while if the word does not appear you add it to the vector and increase the word count
sirlink99
Practically a Master Poster
661 posts since Oct 2010
Reputation Points: 45
Solved Threads: 19
I think you should use split function , to split your paragraph into tokens .
then go through the array you made -by split - Define ArrayList or Vector or some thing like that.
if the value of the String not exist in the ArrayList add it if exist continue .
at the end you return the size of ArrayList .
another solution use SET and return the size of Set directly .
i hope this help you .
AhmedGhazey
Junior Poster in Training
50 posts since Aug 2010
Reputation Points: 2
Solved Threads: 1
The code as posted does not look at or count any words. It needs some work to first find a word and then to count the words.
NormR1
Posting Expert
6,677 posts since Jun 2010
Reputation Points: 1,138
Solved Threads: 656