这可以作为一个数组来检查程序用户输入的字母吗?
final int LOW = 'A'; //smallest possible value
final int HIGH = 'Z'; //highest possible value
int[] letterCounts = new int[HIGH - LOW + 1];
String guessletter;
char[] guessletter;
int offset; //array index
// set constants for the secret word and also "!" to guess the full word
final String GUESS_FULL_WORD = "!";
final String SECRET_WORD = "APPLE";
// set integer value for number of letters for the length of the secret word
// set integer value for the number of guesses the user have made. starting at zero.
int numberofletters, numberofguesses;
numberofguesses = 0;
// guessletter indicates the letter that the user is guessing
// guessword indicates the word that the user is guessing after typing "!"
// new screen indicates the change made to the screen
// screen is the game screen that contains all the "_"'s
String guessletter, guessword, newscreen;
String screen = "";
numberofletters = SECRET_WORD.length ();
/* prompt user for a word */
c.print("Enter a letter: ");
guessletter = c.readLine();
答案 0 :(得分:0)
正如@Bernard指出的那样,您粘贴的代码除了要求用户输入一个字母外没有做任何事情。如果你的问题是你是否在跟踪用户猜到的哪些字母方面是正确的(因此程序不会接受已经猜到的字母),那么是的,你可以使用{{1为此,通过递增与用户猜测的字母对应的数组元素。如果你遇到困难,你应该更清楚问题是什么。