Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2020
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 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 userName = scanner.nextLine();
  8.  
  9. String password = new StringBuffer(userName).reverse().toString();
  10.  
  11. int loginAttemptCount = 1;
  12. String input = scanner.nextLine();
  13. while (!input.equals(password) && loginAttemptCount++ < 4) {
  14. System.out.printf("%nIncorrect password. Try again.");
  15. input = scanner.nextLine();
  16. }
  17.  
  18. if (input.equals(password)) {
  19. System.out.printf("%nUser %s logged in.", userName);
  20. } else {
  21. System.out.printf("%nUser %s blocked!", userName);
  22. }
  23.  
  24. }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement