SHARE
TWEET

Login

elvirynwa Jan 24th, 2019 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Scanner;
  2.  
  3. public class Login {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         String username = scanner.nextLine();
  8.  
  9.         String reversedUsername = "";
  10.  
  11.         for (int i = 0; i < username.length(); i++) {
  12.  
  13.             reversedUsername += username.charAt(username.length() - i - 1);
  14.         }
  15.  
  16.         int counter = 1;
  17.         String inputData = scanner.nextLine();
  18.         while (!inputData.equals(reversedUsername)) {
  19.  
  20.             if (counter++ == 4) {
  21.                 System.out.println(String.format("User %s blocked!", username));
  22.                 return;
  23.             }
  24.  
  25.             System.out.println("Incorrect password. Try again.");
  26.  
  27.             inputData = scanner.nextLine();
  28.         }
  29.  
  30.         System.out.println(String.format("User %s logged in.", username));
  31.     }
  32. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top