Advertisement
psi_mmobile

Untitled

Aug 27th, 2022
1,533
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.02 KB | None | 0 0
  1. public class MyClass {
  2.     public static void main(String args[]) {
  3.         String userName = null;
  4.         String password = null;
  5.         String userNamePassword = "";
  6.         int counter = 0;
  7.         java.util.Scanner scanner = new java.util.Scanner(System.in);
  8.         userName = scanner.nextLine();
  9.         char userNameReverse[] = userName.toCharArray();
  10.         for (int i = userName.length() - 1; i >= 0; i--) {
  11.             userNamePassword += userNameReverse[i];
  12.         }
  13.         while(counter < 4) {
  14.             password = scanner.nextLine();
  15.             if (!userNamePassword.equals(password)) {
  16.                 counter++;
  17.                 if (counter == 4) {
  18.                     System.out.printf("User %s blocked!", userName);
  19.                 } else {
  20.                     System.out.println("Incorrect password. Try again.");
  21.                 }
  22.             } else {
  23.                 System.out.printf("Username %s logged in.",userName);
  24.                 break;
  25.             }
  26.            
  27.         }
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement