我向 Java 大师们提出了另一个棘手的问题
基本上我想要的是:
- 接话;
- 将其转换为 arrayOfChar;
- 将其隐藏为以下方式
_ _ _ _
:
我可以进入第二步,但是当我尝试在下划线中隐藏单词时,它显示为____
而不是_ _ _ _
.
代码:
//Randomly picks word from Array which played
public String pickWord(){
String guessWord = (wordsList[new Random().nextInt(wordsList.length)]);
return guessWord;
}
//Hides picked word
public char[] setWord(){
word = pickWord().toCharArray();
for (int i = 0; i < Array.getLength (word); i++) {
word[i] = '_';
}
return word;
}