Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2020
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Login2 {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6.  
  7. String userName = scanner.nextLine();
  8. String password = "";
  9. boolean isLogged = false;
  10. //posleden simvol //purvi simvol
  11. for (int i = userName.length() - 1; i >= 0 ; i--) {
  12. password += userName.charAt(i); //parolata priscoqva simvolite ot username
  13. } //purvi opit //max broi opiti - 4
  14. for (int i = 1; i <= 4 ; i++) {
  15. String currentPassword = scanner.nextLine();
  16. if (currentPassword.equals(password)) {
  17. System.out.println(String.format("User %s logged in.", userName));
  18. isLogged = true;
  19. break;
  20. } else if (i < 4) {
  21. System.out.println(String.format("Incorrect password. Try again."));
  22. }
  23. }
  24. if (!isLogged) {
  25. System.out.println(String.format("User %s blocked!", userName));
  26. }
  27. }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement