Assignemnt #60 and Enter PIN
Code
/// Name: David Shkolnikov
/// Period: 6
/// Program Name: Enter PIN
/// File Name: EnterPIN.java
/// Date Finished: 12/2/2015
import java.util.Scanner;
public class EnterPIN
{
public static void main( String[] args )
{
Scanner keyboard = new Scanner(System.in);
int pin = 31241;
System.out.println("WELCOME TO THE BANK OF DAVID.");
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();
}
//1. They both only are used at certain times.
//2. A while loop repeats the same thing over and over until it's right.
// An if statement enters it once in that condition.
//3. The variable "entry" is already initialized.
//4. It repeats the while loop an infinite amount of times because there
// is nothing to stop it from repeating.
System.out.println("\nPIN ACCEPTED. YOU NOW HAVE ACCESS TO YOUR ACCOUNT.");
}
}
Picture of the output