Advertisement
thotfrnk

pin.java

Nov 10th, 2022 (edited)
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.36 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class pin {
  3.     public static void main(String[] args) {
  4.  
  5.         //Develop a java program to validate bank PIN of a customer. Use a while loop to repeat code until a valid PIN
  6.         //is entered.
  7.         /*
  8.         *Declare a valid integer PIN
  9.         * Prompt the user to enter the PIN.
  10.         *In a while loop, perform the following steps:
  11.         * Compare the user-entered PIN with the already declared PIN
  12.         * If the entered PIN is not the same, prompt the user to enter the PIN again
  13.         * Repeat the loop until the correct PIN is entered.
  14.         *Print a message confirming that the correct PIN has been entered and that the user now has access to their account.
  15.          */
  16.  
  17.         Scanner input = new Scanner (System.in);
  18.  
  19.         int pin = 1279, user_pin;
  20.  
  21.         System.out.println("Pin Number: ");
  22.         user_pin = input.nextInt();
  23.  
  24.         while(user_pin != 1279) {
  25.  
  26.             if(user_pin != pin) {
  27.                 System.out.println("Incorrect pin. Enter pin again.");
  28.  
  29.                 //System.out.println("Pin Number: ");
  30.                 //user_pin = input.nextInt();
  31.             }
  32.  
  33.             if(user_pin == pin) {
  34.                 System.out.println("Correct pin.");
  35.             }
  36.             System.out.println("Pin Number: ");
  37.             user_pin = input.nextInt();
  38.         }
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement