Advertisement
mark79

Java Fundamentals - Login

May 24th, 2019
528
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.74 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Login {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         String userName = scanner.nextLine();
  8.  
  9.         String password = new StringBuffer(userName).reverse().toString();
  10.  
  11.         int loginAttemptCount = 1;
  12.         String input = scanner.nextLine();
  13.         while (!input.equals(password) && loginAttemptCount++ < 4) {
  14.             System.out.printf("Incorrect password. Try again.%n");
  15.             input = scanner.nextLine();
  16.         }
  17.  
  18.         if (input.equals(password)) {
  19.             System.out.printf("User %s logged in.", userName);
  20.         } else {
  21.             System.out.printf("User %s blocked!", userName);
  22.         }
  23.  
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement