【发布时间】:2011-09-06 10:57:29
【问题描述】:
这是否可以作为一个数组来检查程序用户输入的字母?
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();
【问题讨论】:
-
您的代码不完整(没有任何用处)。
-
另外,它不能编译,因为你有三个(!)
guessletter声明...