Assignment #60: Enter Your PIN
Code
/// Name: Kiran O'Farrell
/// Program Name: Enter your PIN
/// File Name: EnterYourPIN.java
/// Date Completed: 12/3/15
import java.util.Scanner;
public class EnterYourPIN {
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: ");
int entry = keyboard.nextInt();
}
System.out.println("\nPIN ACCEPTED. YOU NOW HAVE ACCESS TO YOUR ACCOUNT.");
}
}
// A "while" loop is like an "if" statement because it triggers on a certain condition.
// However, unlike an "if" statement, it triggers continuously as long as that condition is fulfilled.
// When you delete the "int entry = keyboard.nextInt();" the program infinitely prints INCORRECT PIN. TRY AGAIN. ENTER YOUR PIN:
// This is because the "while" loop triggers the printout continuously.
Picture of the output