Assignemnt #60 Enter Your PIN
Code
///Name: Prooz Fereydouni
///Period: 7
///Project Name: Enter Your PIN
///File Name: EnterPIN.java
///Date: 11/16/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 blocs are similar to if blocs in the sense that both chech to see if a statement is true or false.
//If the statement is true the if statement does what is in the bloc once but the while repeats the bloc until it is not true.
while ( entry != pin )
{
System.out.println("\nINCORRECT PIN. TRY AGAIN.");
System.out.print("ENTER YOUR PIN: ");
//An int is not required becaus the int has already been declared before the while bloc.
//If the line below is removed then the program would not ask for the correct entry and will repeat printing enter your pin.
entry = keyboard.nextInt();
}
System.out.println("\nPIN ACCEPTED. YOU NOW HAVE ACCESS TO YOUR ACCOUNT.");
}
}
Picture of the output