根据用户输入的用户名和密码 进行登录验证 (默认正确的账号为admin 密码123) 有三次输入的机会 给出相应的提示:账号密码无效,请重新输入 登录失败 / 登录成功

public class Lianxi {
public static void main(String[] args) {
int i,j;
Scanner input = new Scanner(System.in);
System.out.println(“请输入用户名和密码:”);
boolean a = false;
for(i=1;i<=3;i++) {
String name = input.next();
String password = input.next();
if(name.equals(“admin”)&&password.equals(“123”)) {
System.out.println(“登录成功!!!”);
a = true;
break;
}else {
System.out.println(“登录失败!!!”);
}
}
if(a==false) {
System.out.println(“三次机会用完,登录失败!!!”);
}
}
}

猜你喜欢

转载自blog.csdn.net/qq_40661543/article/details/113932860