I'm coding in the Java programming language.
The purpose of this code is to go through a set and return an array of all sets of words containing double letters (there should be one for each letter of the alphabet).
This is the code I have so far, right now it's returning the number 23 when it should be returning 26 (again, for each letter of the alphabet). Any guidance on what I'm doing wrong would be so so helpful!
/**
* Returns an array of all sets of words containing double letters,
* one set for each letter of the alphabet. There should be a set
* for all words containing "aa", one for "bb", etc.
* @param words set of words
* @return array of sets, one for each doubled letter in the alphabet
*/
public Set<String>[] allWordSetsContainingDoubleLetters(Set<String> words)
{
Set<String> sets[] = new HashSet[26];
int count = 0;
for (String word : words)
{
String lowerCase = word.toLowerCase();
for (int i = 0; i <= sets.length; i++)
{
char c = (char) ('a' + i);
String str = "" + c + c;
if (lowerCase.contains(str))
{
if (sets[i] == null)
{
sets[i] = new HashSet<String>();
count++;
}
sets[i].add(word);
}
}
}
Set<String> result[] = new HashSet[count];
count = 0;
for (Set<String> s : sets)
{
if (s != null)
{
result[count++] = s;
}
}
return result;
}