Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Lab9_p2 {
- public static void main(String[] args) {
- Scanner input = new Scanner(System.in);
- int[] random = new int[10];
- int[] number = new int[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
- int[] pIN = new int[10];
- int[] password = new int[]{7, 3, 4, 6, 0};
- char[] inNumb = new char[10];
- String[] inNumb1 = new String[10];
- for (int row = 0; row < random.length; row++) {
- random[row] = (int) Math.ceil(Math.random() * 3);
- }
- for (int row = 0; row < pIN.length - 5; row++) {
- pIN[row] = (int) Math.ceil(Math.random() * 3);
- }
- System.out.print("Authentication Process\n\n");
- System.out.print("Number : ");
- for (int row = 0; row < number.length; row++) {
- System.out.printf("%2d", number[row]); // number pad row
- }
- System.out.println();
- System.out.print("Random : ");
- for (int row = 0; row < random.length; row++) {
- System.out.printf("%2d", random[row]); // random number row
- }
- //***********************************************************************
- // Gets user input(String) Converts to Char, then Char value conversion.
- System.out.println();
- System.out.println();
- System.out.print("Enter PIN sequence:");
- String user = input.next();
- for (int i = 0; i < user.length(); i++) { //converts string into char
- inNumb[i] = user.charAt(i);
- }
- System.out.println();
- for (int i = 0; i < user.length(); i++) { //converts from Char to value of char
- inNumb1[i] = String.valueOf(inNumb[i]);
- }
- //*******************************************************************************
- boolean key = false;
- for (int row = 0, match = 0; row < password.length; row++) {
- if (random[password[row]] == Integer.parseInt(inNumb1[row])) {
- match++;
- if (match == 5) {
- key = true;
- }
- }
- }
- if (key) {
- System.out.print("Correct PIN - authentication confirmed.");
- } else {
- System.out.print("Improper PIN - authentication denied.");
- }
- }
- }
- // int[] password = new int []{7,3,4,6,0}; (password)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement