我需要初始化一个密码。而密码不等于保密密码,并且尝试少于三次时会询问用户密码。如果密码正确,打印访问授权,如果密码不正确,打印访问被拒绝,最大尝试次数达到我需要创建一个密码检查器
import java.util.Scanner;
public class PasswordChecker {
public static void main (String [] args) {
Scanner in = new Scanner(System.in);
String secretPassword = "alejandra";
String password;
int attempts = 3;
System.out.println("Please enter password");
password = in.nextLine();
while (!password.equals(secretPassword) && attempts<3)
System.out.println ("incorrect try again");
password = in.nextLine();
if (password.equals (secretPassword)
System.out.println ("access granted");
}
}
我创建了一个无限循环。我是初学者。不知道如何解决它。 – ale
看起来你需要学习使用调试器。请帮助一些[互补调试技术](https://ericlippert.com/2014/03/05/how-to-debug-small-programs/)。如果您之后仍然有问题,请随时返回更多详情。 –
[Password Checker]的可能重复(http://stackoverflow.com/questions/34360580/password-checker) – ale