Advertisement
Katz90

Login

Oct 1st, 2018
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 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 userName = scanner.nextLine();
  8. String userPassword = scanner.nextLine();
  9.  
  10. String backwards = new StringBuilder(userName).reverse().toString();
  11. int counter = 0;
  12.  
  13. while (!userPassword.equals(backwards)) {
  14. System.out.println("Incorrect password. Try again.");
  15. userPassword = scanner.nextLine();
  16. counter++;
  17. if (counter >= 3) {
  18. System.out.printf("User %s blocked!", userName);
  19. break;
  20. }
  21. }
  22. if(userPassword.equals(backwards)){
  23. System.out.printf("User %s logged in.", userName);
  24. }
  25. }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement