Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

Java registration login study notes

Shulou Source: shulou.com Published: 2022-06-03 05:54:03 10月03日 Update

Import java.util.Scanner

/ / user class

Class Users

{

String username

String password

Public Users (String username,String password) {

This.username = username

This.password = password

}

}

Public class LoginDome {

Users user

/ / determine the user name and password

Public boolean userLogin (String username,String password)

{

If (this.user.username.equals (username) & & this.user.password.equals (password))

{

Return true

}

Else

{

Return false

}

}

Public void setUser (Users user)

{

This.user = user

Public static void main (String [] args) {

String username

String password

Int iCount = 0; / / counter determines how many times to log in

Boolean flag = false;// to determine whether the login is successful or not

Scanner in = new Scanner (System.in)

System.out.println ("* user registration *")

System.out.println ("Please enter user name:")

Username = in.nextLine ()

System.out.println ("Please enter password:")

Password = in.nextLine ()

/ / keep the entered user and password

Users u = new Users (username,password)

LoginDome demo = new LoginDome ()

Demo.setUser (u)

System.out.println ("Registration successful!")

System.out.println ("* user login *")

Do {

System.out.println ("Please enter user name:")

Username = in.nextLine ()

System.out.println ("Please enter password:")

Password = in.nextLine ()

If (demo.userLogin (username,password)) / / call the method to determine whether the login is successful or not

{

Break

}

Else

{

ICount + +; / / number of records

If (iCount > = 3 & & flag = = false) / / if login fails more than 3 times

{

System.out.print ("if the login fails more than three times, the program will exit!")

System.exit (0)

}

Else

{

System.out.println ("Please check username and password")

}

}

} while (true)

}

}

* user registration *

Please enter a user name:

Liwen

Please enter your password:

123456

Registered successfully!

* user login *

Please enter a user name:

Li

Please enter your password:

two hundred and twenty two

Please check your user name and password

Tags: User input password login user name success number of times user registration check method program counter note learning Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology Huawei Shulou Information MariaDB macOS