Assignment #60 and Enter Your Pin
Code
/// Name: Graham Pollock
/// Period: 5
/// Program Name: Enter your pin
/// File Name: EnterYourPin.java
/// Date Finished: 9/12/2015/
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 Graham.");
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.");
}
}
///A while loop is imilar to an if statement because it has a condition following it that must be fufilled\
///A whli loop is different from an if statement because it can be used as many times over and over
///Because the variable enter has already been declare an integer in a previous line before the while loop
///If you remove the ability to type the right answer it repeats what the while loop does when you dont type in the right answer
Picture of the output