Assignment #60

Code

///jack newsom
///period 5
///program EnterPIN
///filename EnterPIN.java
///date completed 10/7/15

import java.util.Scanner;

public class EnterPIN
{
    public static void main( String[] args )
    {
        Scanner pinbot = new Scanner(System.in);
        int pin = 12345;
        
        System.out.println("Welcome to the Bank of Dank.");
        System.out.println("Enter your pin: ");
        int entry = pinbot.nextInt();
        
        while ( entry != pin )
        {
            System.out.println("\nIncorrect pin. Try again.");
            System.out.println("Enter your pin: ");
            entry = pinbot.nextInt();
        }
        
        System.out.println("\nPin accepted. You now have access to your account.");
    }
}

///a while loop is similar to an if statement because they both only run if a specified statement is true
///a while loop is different from an if statement because the while loop will run until the argument is false, while an if statement will run only once and only if the statement is true
///there isnt an int in front of entry = pinbot.nextInt(); because entry is already declared earlier in the program as an int
///when the entry = pinbot.nextInt(); line is deleted from the while statement, the while statement runs indefinitely, because it has no code telling it to stop.
      
    

Picture of the output

Assignment X