Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package src;
- 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 = "";
- for (int position = userName.length() - 1; position >= 0; position--) {
- char currentSymbol = userName.charAt(position);
- password += currentSymbol;
- }
- String input = scanner.nextLine();
- int countFailed = 0;
- while (!input.equals(password)) {
- countFailed++;
- if (countFailed == 4) {
- System.out.printf("User %s blocked!", userName);
- break;
- }
- System.out.println("Incorrect password. Try again.");
- input = scanner.nextLine();
- }
- if (input.equals(password)) {
- System.out.printf("User %s logged in.", userName);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment