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 user = scanner.nextLine();
- String pass = new StringBuilder(user).reverse().toString();
- int counter = 0;
- while (true){
- String trying = scanner.nextLine();
- counter++;
- if (trying.equals(pass)){
- System.out.printf("User %s logged in.%n", user);
- return;
- }
- if (counter == 4) {
- System.out.printf("User %s blocked!%n", user);
- return;
- }
- System.out.println("Incorrect password. Try again.");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment