Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Password {
- /**
- * This program will allow the user to validate his PIN number without actually putting in his real PIN numbers.
- */
- public static void main(String[] args) {
- Scanner keyIn = new Scanner (System.in);
- int count = 0;
- final int PASSWORD = 13379; // User's PIN number
- int addition = 1;
- int multiple = 3;
- String comparePassword = Integer.toString(PASSWORD); // Used to compare user input with password.
- //Print intro
- System.out.println("--------------------------------------------------------");
- System.out.println(" Welcome to Vansilli's Trust Bank");
- System.out.println("--------------------------------------------------------");
- System.out.println("\nPlease enter your 5 digit PIN based on the following:");
- //Set an array to print out the range of 10 numbers for the PIN.
- String[] PIN = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"};
- System.out.print("PIN: ");
- for(int j=0;j<PIN.length;j++)
- {
- System.out.print(PIN[j] + " ");
- }
- //Generate 10 random numbers ranging from 1 to 3 under every digit.
- System.out.print("\nNUM: ");
- int[] Num = new int[10];
- for (int index = 0; index<10; index++)
- {
- Num[index] = (int)(Math.random()*multiple + addition);
- System.out.print(Num[index] + " ");
- }
- //We ask the user to input his PIN.
- System.out.print("\nYour PIN:");
- int userInput = keyIn.nextInt();
- //Change the userInput into a string.
- String compareUser = Integer.toString(userInput);
- for(int i = 0; i < 5; i++)
- {
- String s1 = Character.toString(comparePassword.charAt(i));
- String s3 = Character.toString(compareUser.charAt(i));
- for(int j = 0; j < 10; j++)
- {
- String s2 = PIN[j];
- String s4 = Integer.toString(Num[j]);
- if(s1.equals(s2))
- {
- if(s3.equals(s4))
- {
- count++;
- }
- }
- }
- }
- if(count == 5)
- System.out.println("Correct!");
- else
- System.out.println("Invalid!");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement