marking2112

Login

Sep 26th, 2018
382
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.74 KB | None | 0 0
  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 user = scanner.nextLine();
  8.         String pass = new StringBuilder(user).reverse().toString();
  9.  
  10.         int counter = 0;
  11.         while (true){
  12.             String trying = scanner.nextLine();
  13.             counter++;
  14.             if (trying.equals(pass)){
  15.                 System.out.printf("User %s logged in.%n", user);
  16.                 return;
  17.             }
  18.             if (counter == 4) {
  19.                 System.out.printf("User %s blocked!%n", user);
  20.                 return;
  21.             }
  22.             System.out.println("Incorrect password. Try again.");
  23.  
  24.         }
  25.  
  26.  
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment