Assignment #60 and Enter Your PIN

Code

    /// Name: Ali Kurland
    /// Period: 6
    /// Program Name: Enter Your PIN
    /// File Name: EnterPIN.java
    /// Date Finished: 10/8/2015
    
    //1. A while loop is similar to an if statement because both run a portion of code only if the conditions next to the "while" or "if" in the code are met.
    //2. Unlike an if statement, a while loop repeats until the conditions next to the "while" in the code are no longer true.
    //3. There is no int inside the while loop because entry has already been defined before the loop.
    //4. When the line entry = keyboard.nextInt() is deleted from iside the while loop, an incorrect PIN causes the while loop to loop infinitely. This is because there is no longer a way to re-enter the PIN, meaning that the PIN will be recognized as incorrect indefinitely and the "while" conditions will always be met, causing this portion of code to run repeatedly.
    
    import java.util.Scanner;
    
    public class EnterPIN
    {
    	public static void main( String[] args )
    	{
    		Scanner keyboard = new Scanner(System.in);
    		int pin = 12345;
    
    		System.out.println("WELCOME TO THE BANK OF ALI.");
    		System.out.print("ENTER YOUR PIN: ");
    		int entry = keyboard.nextInt();
    
    		while ( entry != pin )
    		{
                  System.out.println("\nINCORRECT PIN. TRY AGAIN.");
                  System.out.print("ENTER YOUR PIN: ");
                  entry = keyboard.nextInt();
    		}
    
    		System.out.println("\nPIN ACCEPTED. YOU NOW HAVE ACCESS TO YOUR ACCOUNT.");
    	}
    }
    

Picture of the output

Assignment 60