这是拼写检查器中的一种方法。正如标题所解释的,当且仅当所有添加到 arraylist 的单词都在父数组 words 中找到时,它才应该返回 true。否则它应该返回一个假值。我已经为此奋斗了几个小时,这就是我目前的情况......
/**
* This method returns true if (and only if) all words in the
* given wordList are found in the dictionary.
*/
public boolean allKnown(ArrayList<String> wordList)
{
boolean result = true;
for(int index = 0; index < wordList.size(); index++)
{
if(words.contains(!wordList.contains(index)))
{
result = false;
}
result = true;
}
return result;
}
我真正需要的只是一种判断是或否的方法,但我迷路了。请尝试使用给出的代码,因为这是教授该代码的练习。谢谢!