1. Establish input scanning
Use the Scanner class in java to obtain input data. The specific code is as follows:
Scanner scan = new Scanner(System.in);
2. Receive user name
Create a prompt message to prompt for a user name and store the entered user name. The code is as follows:
System.out.println("请输入登陆用户名:"); String usename=scan.nextLine();
3. Receive password
Create a prompt message to prompt for a password and store the entered password. The code is as follows:
System.out.println("请输入登陆的密码:"); String password=scan.nextLine();
4. Verification information
Use the if else statement to verify the user name and password, and print the prompt information. The code is as follows:
if(!usename.equals("me")){ System.out.println("用户名非法。"); }else if(!password.equals("123456")){ System.out.println("登陆密码错误。"); }else{ System.out.println("恭喜您,登陆信息通过验证。"); }
Complete!
Recommended tutorial: java quick start
The above is the detailed content of How to implement verification function in java. For more information, please follow other related articles on the PHP Chinese website!