Java-Hangman游戏-StringBuffer变量上的charAt问题

Java-Hangman游戏-StringBuffer变量上的charAt问题,java,char,stringbuffer,charat,Java,Char,Stringbuffer,Charat,所以我尝试用一个返回随机单词的网站来制作一个吊死人游戏。我在《刽子手》游戏中用了这个随机词 我坚持的是验证用户的猜测。这是代码,我只是先把所有的东西都放在main中,然后在完成这项工作之后,为我创建单独的方法来完成这项工作 public static void main(String[] args) throws Exception { randomWord = TestingStuff.sendGet(); int totalTries = 1; char[] gues

所以我尝试用一个返回随机单词的网站来制作一个吊死人游戏。我在《刽子手》游戏中用了这个随机词

我坚持的是验证用户的猜测。这是代码,我只是先把所有的东西都放在main中,然后在完成这项工作之后,为我创建单独的方法来完成这项工作

public static void main(String[] args) throws Exception {
    randomWord = TestingStuff.sendGet();
    int totalTries = 1;
    char[] guesses = new char[26];
    int length = randomWord.length();
    Scanner console = new Scanner(System.in);

    System.out.print("* * * * * * * * * * * * * * *"
            + "\n*    Welcome to Hangman!    *"
            + "\n* * * * * * * * * * * * * * *");
    System.out.println("\nYou get 10 tries to guess the word by entering in letters!\n");
    System.out.println(randomWord);
    /*
     Cycles through the array based on tries to find letter
     */
    while (totalTries <= 10) {
        System.out.print("Try #" + totalTries);
        System.out.print("\nWhat is your guess? ");
        String guess = console.next();
        char finalGuess = guess.charAt(0);
        guesses[totalTries - 1] = finalGuess; //Puts finalGuess into the array


            for (int i = 0; i < totalTries; i++) { //checks to see if the letter is already guessed
                if (finalGuess != guesses[i]) {
                    for (int j = 0; i < length; j++) { //scans each letter of random word
                        if (finalGuess.equals(randomWord.charAt(j))) {

                        }
                    }
                } else {
                    System.out.println("Letter already guessed, try again! ");
                }
            }
        }
    }
publicstaticvoidmain(字符串[]args)引发异常{
randomWord=TestingStuff.sendGet();
整数=1;
char[]猜测=新字符[26];
int length=randomWord.length();
扫描仪控制台=新扫描仪(System.in);
系统输出打印(“*********”
+“\n*欢迎来到刽子手!”
+“\n*******”;
System.out.println(“\n通过输入字母,您可以尝试猜10次!\n”);
System.out.println(随机字);
/*
根据查找字母的尝试在数组中循环
*/

虽然(totaltrys
finalGuess
是一个基本的
char
,但不能在其上使用
equals
等方法。只需使用
=
运算符比较两个
char

if (finalGuess == randomWord.charAt(j)) {
if (finalGuess == randomWord.charAt(j)) {