Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.92 KB | None | 0 0
  1. package BasicSyntax;
  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.  
  11.         String password = "";
  12.  
  13.         for (int i = username.length() - 1; i >= 0; i--) {
  14.             password += username.charAt(i);
  15.         }
  16.  
  17.         String inputPassword = scanner.nextLine();
  18.         int count = 1;
  19.         while (!inputPassword.equals(password)) {
  20.             count++;
  21.             System.out.println("Incorrect password. Try again.");
  22.             inputPassword = scanner.nextLine();
  23.             if (count == 4) {
  24.                 break;
  25.             }
  26.         }
  27.         if (inputPassword.equals(password)) {
  28.             System.out.println("User " + username + " logged in.");
  29.         } else {
  30.             System.out.println("User " + username + " blocked!");
  31.         }
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement