Advertisement
NadezhdaGeorgieva

05.Login

Sep 18th, 2020
1,058
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.98 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.lang.StringBuilder;
  3.  
  4.  
  5. public class ZLogin {
  6.     public static void main(String[] args) {
  7.         Scanner sc = new Scanner(System.in);
  8.         StringBuilder username = new StringBuilder(sc.nextLine());
  9.  
  10.         StringBuilder correctPassword = new StringBuilder(username);
  11.         correctPassword.reverse();
  12.         int count = 1;
  13.         while(count <= 4){
  14.             String password = sc.nextLine();
  15.  
  16.             int comparison = password.compareTo(correctPassword.toString()); //returns 0 if it's true, negative digit if it's false
  17.             // use compareTo for Strings
  18.             if (0 == comparison){
  19.                 System.out.printf("User %s logged in.", username);
  20.                 break;
  21.             }else if(count < 4 ){
  22.                 System.out.println("Incorrect password. Try again.");
  23.             }else{
  24.                 System.out.printf("User %s blocked!", username);
  25.             }
  26.             count++;
  27.         }
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement