Didart

Login

Sep 20th, 2021
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.02 KB | None | 0 0
  1. package src;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Login {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.  
  9.         String userName = scanner.nextLine();
  10.         String password = "";
  11.  
  12.         for (int position = userName.length() - 1; position >= 0; position--) {
  13.             char currentSymbol = userName.charAt(position);
  14.             password += currentSymbol;
  15.  
  16.         }
  17.             String input = scanner.nextLine();
  18.             int countFailed = 0;
  19.             while (!input.equals(password)) {
  20.                 countFailed++;
  21.                 if (countFailed == 4) {
  22.                     System.out.printf("User %s blocked!", userName);
  23.                     break;
  24.                 }
  25.                 System.out.println("Incorrect password. Try again.");
  26.                 input = scanner.nextLine();
  27.             }
  28.  
  29.             if (input.equals(password)) {
  30.                 System.out.printf("User %s logged in.", userName);
  31.             }
  32.         }
  33.     }
  34.  
  35.  
  36.  
Advertisement
Add Comment
Please, Sign In to add comment