import java.util.Scanner;
public class Test2 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
for(int i = 0; i < 3; i++) {
System.out.println("请输入用户名:");
String userName = sc.nextLine();
System.out.println("请输入密码:");
String password = sc.nextLine();
if("admin".equals(userName) && "admin".equals(password)) {
System.out.println("欢迎" + userName + "登录");
break;
}else {
if( i == 2) {
System.out.println("您的错误次数已到,请明天再来吧");
}else {
System.out.println("录入错误,您还有" + (2 - i) + "次机会");
}
}
}
} |