public class StringTest2 {
public static void main(String[] args) {
String name = "admin";
String pwd = "admin";
// x=0,1,2
for (int x = 0; x < 3; x++) {
Scanner sc = new Scanner(System.in); 它为什么要放在for循环中呢
System.out.println("请输入用户名:");
String username = sc.nextLine();
System.out.println("请输入密码:");
String password = sc.nextLine();
if (name.equals(username) && pwd.equals(password)) {
System.out.println("登录成功,你就可以开始完猜数字小游戏了");
Game.palyGame();
break;
} else {
// 2,1,0
if ((2 - x) == 0) {
System.out.println("帐号被锁定,请与管理员联系");
} else {
System.out.println("登录失败,你还有" + (2 - x) + "次机会");
}
}
}
}
}
|
|