所以我应该做的是用户输入一个字母并且程序检查该字母是否是单词的一部分,从那里我无法弄清楚我需要使用什么代码来显示其中一个字母本身就是我到目前为止所拥有的
do {
System.out.println("Word: " + secretWord.getWordMask());
//System.out.print("Guesses: " + guesses);
System.out.print("Enter your guess: ");
Scanner keyboard = new Scanner(System.in);
String guess = keyboard.next();
WordHider revealChar = new WordHider();
System.out.println(revealChar.revealLetter(guess));
//if (secretWord.revealLetter(guess));
} while (secretWord.isHiddenWordFound());
这是给我的一个类的另一部分,我必须弄清楚如何将它称为方法并实现它
public int revealLetter(String letter) {
int count = 0;
String newFoundWord = "";
if (letter.length() == 1) {
for (int i = 0; i < secretWord.length(); i++) {
if ((secretWord.charAt(i) == letter.charAt(0))
&& (wordMask.charAt(i) == HIDE_CHAR.charAt(0))) {
count++;
newFoundWord += letter;
}
else {
newFoundWord += wordMask.charAt(i);
}
}
}
wordMask = newFoundWord;
return count;
我的主要问题就在第一部分,我WordHider revealChar = new WordHider();
System.out.println(revealChar.revealLetter(guess));
应该做的是揭示我的信,但它绝对不正确,有什么想法吗?