Speed up development with full-stack environments for every branch.

Learn More

A Basic While Loop (Java Example)

Forked from Basic Java Example.

626 Runs 717 Views 159 Copies

This program uses a while loop to repeatedly ask the user to enter a PIN number until they enter the correct combination.

Saved

Saved

dsa377 12

dsa377
published a year ago

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 SPRING WOODS CREDIT UNION.");
		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.");
  }
}
 

Please login/signup to get access to the terminal.

Your session has timed out.

Dismiss (the page may not function properly).