public class Main {
public static void main(String[] args) {
System.out.println("You have three attempts to enter the password.");
comparePass(0);
}
private static void comparePass(int attemptsUser) {
Scanner in = new Scanner(System.in);
String pass = new StringC'yourPassword");
String userPass;
int attempts = attemptsUser; int tries;
System.out.println("Please, input password:"); userPass = in.nextO;
if (pass.equals(userPass)) {
System.out.printlnC'Allowed access!");
} else {
attempts += 1; tries = 3 - attempts;
System.out.printlnC'Password incorrect! Left" + tries +" attempts.");
if (attempts < 3) {
comparePass(attempts);
} else {
System.out.println("You enter the password incorrectly three times. Access denied!");
return;
}
}
}
Comments
Leave a comment