我是Java的新手,我不明白为什么我的程序无法正常工作

时间:2013-12-04 19:28:03

标签: java

为什么即使与我输入的密码相同,我的密码也显示错误? 密码是通过的,我写了密码,但它告诉我这是错误的。

import java.util.Scanner;
public class App
{
    public static void main(String[] args)
    {
        System.out.println("Guess the word: ");
        Scanner test = new Scanner(System.in);

        String guessThePassword = test.nextLine();
        System.out.println("You wrote: " + guessThePassword);

        String correctPasswordIs = "pass";
        System.out.println("The correct password is: " + correctPasswordIs);

        if  (guessThePassword == correctPasswordIs)
            {
            System.out.println("The password you wrote is right");
            }
        else 
            {
            System.out.println("The password you wrote is wrong");
            }
        test.close();
    }
}

0 个答案:

没有答案