Programming Assignment #60

Code

/// Name: Dylan Sleeper
/// Period: 6
/// Program Name: EnterPIN
/// File Name: EnterPIN.java
/// Date Finished: 10/22/2015

//A while loop is similar to an if statement because it also contains a conditional and it will not run the code unless that is true.
//It is different because it loops while the statement stays true.
//Because the variable has already been initialized.
//When I get rid of it, it just loops endlessly because the entry will always not equal the PIN.

import java.util.Scanner;

public class EnterPIN
{
	public static void main( String[] args )
	{
		Scanner keyboard = new Scanner(System.in);
		int pin = 12346;

		System.out.println("WELCOME TO THE BANK OF AMAZINGNESS.");
		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.");
	}
}
  

Outputs

Assignment 15