Advertisement
Krassi_Daskalova

Login_password

May 24th, 2019 (edited)
338
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 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 password = "";
  9. for(int i = userName.length() - 1; i >= 0; i--){
  10. password = password + userName.charAt(i);
  11. }
  12. int loginAttemptCount = 1;
  13. String input = scanner.nextLine();
  14. while (!input.equals(password) && loginAttemptCount++ < 4) {
  15. System.out.printf("Incorrect password. Try again.%n");
  16. input = scanner.nextLine();
  17. }
  18. if (input.equals(password)) {
  19. System.out.printf("User %s logged in.", userName);
  20. } else {
  21. System.out.printf("User %s blocked!", userName);
  22. }
  23. }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement