dimanche 6 janvier 2019

Is there anyway I could stop my loop looping

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..when I try to insert the correct pass which is 1234 "Access granted". However, when I try to insert it after multiple attempts it will output Access Denied which should not.

if (pass != code) {
   while (ct < 2) {
       ct++;
       access.denied();
       reEnter.Enter1();
   } access.ct1();
   } else {
   access.granted();
   }

    }
   }

Aucun commentaire:

Enregistrer un commentaire