Home > Java > JavaBase > How to implement verification function in java

How to implement verification function in java

王林
Release: 2019-11-20 09:47:09
Original
2877 people have browsed it

How to implement verification function in java

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);
Copy after login

How to implement verification function in java

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();
Copy after login

How to implement verification function in java

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();
Copy after login

How to implement verification function in java

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("恭喜您,登陆信息通过验证。");
}
Copy after login

How to implement verification function in java

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template