Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Login {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String userName = scanner.nextLine();
- String password = new StringBuffer(userName).reverse().toString();
- int loginAttemptCount = 1;
- String input = scanner.nextLine();
- while (!input.equals(password) && loginAttemptCount++ < 4) {
- System.out.printf("Incorrect password. Try again.%n");
- input = scanner.nextLine();
- }
- if (input.equals(password)) {
- System.out.printf("User %s logged in.", userName);
- } else {
- System.out.printf("User %s blocked!", userName);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement