/**
- 验证登录信息的合法性
- @author asus
- 在main方法中接收用户输入的登录用户名与登录密码,然后通过if条件语句
- 分别判断用户名与密码,并输出登录验证结果。
*/
代码如下:
package package3;
import java.util.Scanner;
/**
* 验证登录信息的合法性
* @author asus
* 在main方法中接收用户输入的登录用户名与登录密码,然后通过if条件语句
* 分别判断用户名与密码,并输出登录验证结果。
*/
public class CheckLogin {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner scan=new Scanner(System.in);//创建扫描器
System.out.println("请输入登录用户名:");
String username=scan.nextLine();//接收用户输入登录名
System.out.println("请输入登录密码:");
String password=scan.nextLine();//接收用户输入登录密码
if(!username.equals("mr")) {//判断用户名的合法性
System.out.println("用户名非法。");
}else if(!password.equals("mrsoft")) {//判断密码的合法性
System.out.println("登录密码错误。");
}else {//通过以上两个条件判断则默认通过登录验证
System.out.println("恭喜您,登录信息通过验证。");
}
}
}