Assignment 60

Code

    import java.util.Scanner;

    public class EnterYourPIN
    {
        public static void main(String[] args)
        {
            Scanner keyboard = new Scanner(System.in);
            int pin = 12345;
            
            System.out.print("Enter your pin: ");
            int entry = keyboard.nextInt();
            
            while (entry != pin)
            {
                System.out.println("\nIncorrect, try again:");
                System.out.print("Enter your pin: ");
                entry = keyboard.nextInt();
            }
            
            System.out.println("\nPin Accepted. Wait for your account to load.");
        }
    }


    //While loop continues to run when you type something in the input
    //While loop continues to run when you get something wrong, while the if statement doesnt.
    //entry is already am int variable outside of the while loop
    //while loop continues to run nonstop
    

Picture of the output

Assignment