Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String user = scanner.nextLine();
- String password = "";
- for (int i = user.length() - 1; i >= 0; i--) {
- password += user.charAt(i);
- }
- int tryout = 0;
- while (true) {
- String input = scanner.nextLine();
- if (input.equals(password)) {
- System.out.printf("User %s logged in.", user);
- break;
- } else {
- System.out.println("Incorrect password. Try again.");
- }
- tryout++;
- if (tryout > 4) {
- System.out.printf("User %s blocked!", user);
- }
- }
- }
- }
- //5. Login
- //You will be given a string representing a username. The password will be that username reversed. Until you receive the correct
- // password print on the console "Incorrect password. Try again.". When you receive the correct password print "User {username} logged
- // 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