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

How to implement verification function in java

王林
王林Original
2019-11-20 09:47:092883browse

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);

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();

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();

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

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!

Statement:
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