帮助。我是 Java 编程的新手,所以我会尽量利用你的术语。我想知道如何让这个程序注册为真的。当我输入“密码”作为输入时,它不会执行“if”正文中的任何代码。我还将这段代码粘贴到另一个类中,无论如何它仍然不起作用。
我在这个程序上工作了大约半个小时,调试它的时间是原来的两倍。请仔细阅读编码。
import java.util.Scanner;
public class whileloop {
public void whileloop1() {
//DEBUG THIS PROGRAM! "password" does not work for input
System.out.println("Please enter the password to continue: ");
Scanner password = new Scanner(System.in);
String passwordinput = password.nextLine();
System.out.println("This is your entered password: " + passwordinput);
if (passwordinput == "password") {
System.out.println("Startup sequence has been iniciated.");
System.out.println("System is working correctly.");
//Terminate all here ---
} else {
System.out.println("Wrong password! Terminating program. /END");
}
System.out.println("Supressing the program's scanner!");
password.close();
}
}