Advertisement
Guest User

05.Login

a guest
Jan 25th, 2019
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4.  
  5. public static void main(String[] args) {
  6.  
  7. Scanner scanner = new Scanner(System.in);
  8. String user = scanner.nextLine();
  9.  
  10. String password = "";
  11. for (int i = user.length() - 1; i >= 0; i--) {
  12. password += user.charAt(i);
  13. }
  14.  
  15. int tryout = 0;
  16.  
  17. while (true) {
  18.  
  19. String input = scanner.nextLine();
  20.  
  21. if (input.equals(password)) {
  22. System.out.printf("User %s logged in.", user);
  23. break;
  24. } else {
  25. System.out.println("Incorrect password. Try again.");
  26. }
  27. tryout++;
  28.  
  29. if (tryout > 4) {
  30. System.out.printf("User %s blocked!", user);
  31. }
  32. }
  33.  
  34. }
  35. }
  36.  
  37. //5. Login
  38. //You will be given a string representing a username. The password will be that username reversed. Until you receive the correct
  39. // password print on the console "Incorrect password. Try again.". When you receive the correct password print "User {username} logged
  40. // in." However on the fourth try if the password is still not correct print "User {username} blocked!" and end the program.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement