比较字符串输入

时间:2014-01-21 01:54:59

标签: java

我不确定为什么guesswords[random][0]相同,即使我输入了正确的答案。它会跳过if语句并转到else

    do{

System.out.println("The scrambled word is: " + scramble[random]);

                Scanner fooBar = new Scanner(System.in);

                System.out.println("What is this word?: ");
                guess = fooBar.next();

                if(guess == words[random][0])
                {
                    System.out.println("Congratulations, you have guessed correctly!");
                    done = true;
                }
            else
                System.out.println("Sorry, that is not it.");

            }while(done == false);

0 个答案:

没有答案