0
這將工作作爲一個數組來檢查程序的用戶輸入的字母?這個數組是否可以檢查用戶輸入的字母?
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();
您的代碼不完整(沒有做任何有用的事情)。 – Bernard 2011-06-01 16:26:13
另外,它不會編譯,因爲你有三個(!)聲明'guessletter' ... – 2011-06-01 16:49:53