Когда я пытаюсь вставить правильный проход, который равен 1234 «Доступ разрешен».
Однако, когда я пытаюсь вставить его после нескольких попыток, он выдаст «Отказано в доступе», чего не должно быть.
import java.util.*;
class access {
void granted () {
System.out.println("Access Granted!");
}
void denied() {
System.out.println("Access Denied!");
System.out.println("Please try again! Re-enter your passcode: ");
}
void ct1 () {
System.out.println("System is disabling now due to multiple attempts made");
}
}
class passEnter extends Passcode {
void Enter1 () {
Scanner sc = new Scanner(System.in);
super.pass = sc.nextInt();
}
}
public class Passcode {
static int code = 1234;
static int pass;
public static void main (String [] agrs) {
access access = new access();
passEnter reEnter = new passEnter();
int ct = 0;
System.out.println("Enter your passcode ");
reEnter.Enter1();
// This is where my problem begins...
if (pass != code) {
while (ct < 2) {
ct++;
access.denied();
reEnter.Enter1();
}
access.ct1();
}
else {
access.granted();
}
}
}