package com.Caishuzi;
import java.util.Scanner;
public class Login {
public static void main(String[] args) {
//定义用户名和密码---已经存在的用户名和密码
String username = "admin";
String password = "admin";
int randomNum = (int)(Math.random()*100+1);
//给三次机会
for(int x = 0; x < 3; x++) {
//x = 0,1,2
//键盘录入用户名和密码
Scanner input = new Scanner(System.in);
System.out.println("请输入用户名:");
String name = input.nextLine();
System.out.println("请输入密码:");
String pass = input.nextLine();
//比较用户名和密码
if(name.equals(username) && pass.equals(password)) {
//如果都相等
System.out.println("恭喜您登陆成功!");
while(true) {
System.out.println("请输入您猜的数字(1~100):");
int num = input.nextInt();
if(num > randomNum) {
System.out.println("猜大了");
}else if(num < randomNum) {
System.out.println("猜小了");
}else {
System.out.println("恭喜你,猜对了");
break;
}
}
}
else {
if((2-x) == 0) {
System.out.println("账号已经被锁定,请与班长联系");
}else {
System.out.println("登陆失败,你还有:"+(2-x)+"次机会");
}
}
}
}
}
11-06
2083
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
03-29