Assignemnt #60: While Loops with a PIN
Code
/// Name: Sean Harrison
/// Period: 7
/// Program name: EnterPIN
/// File Name: EnterPIN.java
/// Date Finished: 11/20/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 Community Bank, N.A. " );
System.out.print( "Enter your PIN please " );
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.print( "\nPIN accepted. You now may acess your bank account. " );
}
}
/// A while loop is similar to an if statement, in the sense both are looking for specific conditions to be fufilled.
/// A while loop differentiates from an if statement, in the sense that is does not rely upon a condition it merely will keep repeating itself until the desired input is inputted.
/// The entry password had alread already been inputted as the PIN beforehand, is not part of the Loop.
/// the program loops the system.out.println over and over and over, it doesnt allow for another input.
Picture of the output