家庭作业:我们正在研究一个刽子手计划。我有以下方法:
public char[] selectWord()
{
String[] hangmanWords = new String[50] { "time", "person", "year", "way", "day", "thing", "man", "world", "life", "hand", "part", "child", "eye", "woman", "place", "work", "week", "case", "point", "government", "company", "number", "group", "problem", "fact", "good", "new", "first", "last", "long", "great", "little", "own", "other", "old", "right", "big", "high", "different", "small", "large", "next", "early", "young", "important", "few", "public", "bad", "same", "able" };
Random wordIndex = new Random();
int randomIndex = wordIndex.Next(0, 49);
wordToGuess = hangmanWords[randomIndex].ToUpper();
char[] wordToGuessArray = wordToGuess.ToCharArray(); // convert word to array of letters
return wordToGuessArray;
}
我想为wordToGuessArray
. 理想情况下,我想要selectWord()
设置wordToGuessArray
参数的方法。但是,在运行此方法之前,我不会知道可变数组长度,并且如果没有明确定义,我将无法创建构造函数char[x]
。这个问题在 main.xml 中设置了数组长度。由于任务中的要求限制,我的不能。那么这种selectWord()
方法需要在哪里才能正确使用set
我的变量?
我很难想象一个可行的程序流程。