public class Text {
/**
* @param args
*/
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
for (int i = 0; i < 3; i++) {
System.out.println("请输入用户名:");
String userword = sc.nextLine();
System.out.println("请输入密码:");
String passwork = sc.nextLine();
if ("admin".equals(userword)&&"admin".equals(passwork)) {
System.out.println("欢迎"+userword+"登录。");
break;
} else {
if(i==2){
System.out.println("错误次数已达上限,暂停服务。");
} else {
System.out.println("用户名或密码错误,请重新输入。");
System.out.println("您还有"+(2-i)+"次输入机会。");
}
}
}
}
}
|
|