Strings - Repeated Word

So here is the code requested. 

For this function, a word is recognized if the length of its characters is greater than one. So basically, to look for repeated words, first thing to do is know all combination of these words.

To look for these words, what I did was to get the substring of the entered string with 3 in length up to its maximum length. Since in java, the String class doesn't have any methods for substring, we I converted the String class object to a StringBuffer object. The stack is just used to determine if there is a repeated word(if stack is empty, no repeatitions).

After determining the word, we then traverse the string starting from start to the end comparing the newly found word and the substrings of specified index retrieved during the traversing.

The code:


The problem for this code though is that it recognizes spaces as part of the word.
A solution would be to separate all words then put it on a stack then base the searches on these grouped words.

2 comments:

Anonymous said...

so are you suggesting anagrams for this particular application???could you create a source code that would have a recursive function that would get all the anagrams 0f the string.??


*opensourceJavaForPros

Tyanak said...

nope. not necessarily using anagrams, since the application does not scramble the words. About the anagrams, yup, i think i have one application in java for that. Ill be posting it soon.

Post a Comment