Enter Your PIN
Code
/// Name: Rachel Smith
/// Period: 5
/// Program Name: Enter Your PIN
/// File Name: EnterPIN.java
/// Date Finished: 11/19/2015
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 JOSHUA.");
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.");
}
}
/// 1. A While loop is like an if statement because it's like if ( entry != pin ) entry doesn't equal pin then run the while loop until it does.
/// 2. It's different from an if statement because it can run more than once.
/// 3. Entry is defined as an integer on line 17 so putting int on line 23 is superfluous.
/// 4. The while loop continues to run because entry stays defined as it was originally.
Picture of the output