Advertisement
CoineTre

JF-ExcBasic05. Login

Jan 14th, 2021
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.82 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Ex5Reverse {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         String user = scanner.nextLine();
  7.         String pass = "";
  8.         for (int i = user.length() -1; i >=0; i--) {
  9.             pass += user.charAt(i);
  10.         }
  11.         boolean logged = false;
  12.         for (int i = 0; i < 4; i++) {
  13.             String input = scanner.nextLine();
  14.             if (input.equals(pass)){
  15.                 logged = true;
  16.                 System.out.printf("User %s logged in.",user);
  17.                 break;
  18.             }
  19.             if (i < 3) {
  20.                 System.out.println("Incorrect password. Try again.");
  21.             }
  22.         }
  23.         if (!logged) {
  24.             System.out.printf("User %s blocked!", user);
  25.         }
  26.     }
  27. }
  28.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement