Advertisement
desislava_topuzakova

05. Login

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