当您输入正确的值时,为什么此循环始终返回false?

时间:2015-06-23 04:02:18

标签: java

import java.util.Scanner;
public class Password {
    public static void main(String[] args) {
         Scanner reader = new Scanner(System.in);

        System.out.println("Please create a password");
        String pw = reader.nextLine();

        while (true) {
            System.out.println("Enter the password");
            String pwt = reader.nextLine();
            if (pwt == pw) {
            System.out.println("The password is correct!");
                break;
            } else {
                System.out.println("The password is incorrect, please try again");

            }
        }
    }
}

我对此不熟悉,所以答案可能很明显,但当我输入正确的密码时,我只是不明白为什么它会显示为错误

0 个答案:

没有答案