1

I've tried to make a login form with 3 maximum attempts. But whenever the first login attempt fail (When Username Or Password didn't match), the next attempt always skip the Username inputting session and just jumps into the Password inputing session. How do I fix this?

import java.util.Scanner;

public class LogInForm
{
   public static void main(String args[])
   {
       int X;
       Scanner Input1 = new Scanner(System.in);

       X = 1;

       do
       {
          System.out.print("Type your username = ");
          String Username = Input1.nextLine();

          System.out.print("Type your password = ");
          int Password = Input1.nextInt();

          if((Username.equals("Zaza555"))&&Password==2151)
          {
              System.out.println("\nLog in successful");
              X = X + 3;
          }

          else
          {
              System.out.println("=====\nUsername or password doesn't match\n=====");
              X++;
          }
      }
      while(X<=3);
   }
}

and here are the output :

Type your username = Zaza55

Type your password = 21

Username or password doesn't match

Type your username = Type your password = 31

Username or password doesn't match

Type your username = Type your password = 43

Username or password doesn't match

Process finished with exit code 0

Community
  • 1
  • 1

0 Answers0