Advertisement
mitko30009

5. Login

Sep 21st, 2019
319
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.90 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Ex5 {
  4.     public static void main(String[] args) {
  5.         Scanner sacnner = new Scanner(System.in);
  6.  
  7.         String username = sacnner.nextLine();
  8.         String password = "";
  9.         String passwordTry = "";
  10.         int counter1 = 0;
  11.  
  12.         for (int counter = username.length() - 1; counter >= 0;counter--){
  13.             password += username.charAt(counter);
  14.         }
  15.  
  16.         while (!(passwordTry.equals(password)) && counter1 < 4){
  17.             passwordTry = sacnner.nextLine();
  18.             counter1++;
  19.             if (passwordTry.equals(password)){
  20.                 System.out.printf("User %s logged in.",username);
  21.                 return;
  22.             }
  23.             if (counter1 <= 3) {
  24.                 System.out.println("Incorrect password. Try again.");
  25.             }
  26.         }
  27.         System.out.printf("User %s blocked!",username);
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement