阅读背景:

ava.lang。StringIndexOutOfBoundsException:字符串索引超出范围:9 at java.lang. strat . charat (String.java:658)

来源:互联网 

So I have this piece of code.

我有这段代码。

class Hangman {
public static void main(String[] args) {
    char LetterGuess;
    int x;
    int num = 0;                                    //Number of letters in a word
    int y = 0; //(int)(Math.random() * 16 );
    char CurrLet;
    String word = "yes" ;
    byte[] Guess = new byte[15];

    switch(y) {

        case 0:
            word = "blindfold" ;
            num = word.length();
            break;
    }
    for(boolean guessed = false; guessed = true;) {

        for(x = 0; x < num +1; x++) {
                 if(Guess[x] == 1) {
                    CurrLet = word.charAt(x);
                    System.out.print(CurrLet);
                 } else {
                     System.out.print(" _");
            }
        }

         System.out.println("");
         System.out.println("");
         LetterGuess = Keyboard.readChar();

         for(x = 0; x < num +1; x++) {
            CurrLet = word.charAt(x);
            if(LetterGuess == CurrLet) {
                Guess[x] = 1;
            }
         }


    }

}
class



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: