This code is supposed to find the nth short word
For example, if you are passed an array containing the words
"Mary", "had", "a", "little", "lamb"
and you are asked to return the second word, you would return
"a"
Below is my attempt to solve this but im pretty confused and dont know what im doing.
Any help would be greatly appreciated. thanks
public class Words
{
/**
Returns the nth short word (length <= 3) in an array.
@param words an array of strings
@param n an integer > 0
@return the nth short word in words, or the empty string if there is
no such word
*/
public String nthShortWord(String[] words, int n)
{
String tempWord = "";
if(words.length <=3)
{
for (int i = 0; i < words.length; i++)
{
return tempWord;
}
}
else if(n > words.length)
{
return "";
}
return tempWord;
}
}