![](/img/trans.png)
[英]When I enter wrong userid or password, It just say **Please enter user id and password**
[英]I want that it should stop when the user entered 3 times wrong ID and Password (ID and PW are correct ones)
在我的程序中,當用戶輸入了3次錯誤的ID和密碼(ID和PW是正確的)時,它就結束了-結束沒有問題-同時在說出“您的帳戶有被阻止”。
Scanner enter = new Scanner(System.in);
String ID2, PW2, PW = "qwerty123", ID = "theman" ;
int entry=0;
do {entry++;
System.out.println("Please enter you ID.");
ID2 = enter.nextLine();
System.out.println("Please enter your password.");
PW2 = enter.nextLine();
if(!(ID.equals(ID2)) && ((PW.equals(PW2)))) {
System.out.println("Try again!");
}
else if((ID.equals(ID2)) && (!(PW.equals(PW2)))) {
System.out.println("Try again!");
}
else if(!(ID.equals(ID2)) && !((PW.equals(PW2)))) {
System.out.println("Try again!");
}
if(entry==3) {
System.out.println("**Your account has been blocked**");
break;
}
}while(!(ID.equals(ID2)) && !((PW.equals(PW2))));
System.out.println("Welcome...");
嘗試這個;
Scanner enter = new Scanner(System.in);
String ID2, PW2, PW = "qwerty123", ID = "theman";
int entry = 0;
do {
entry++;
System.out.println("Please enter you ID.");
ID2 = enter.nextLine();
System.out.println("Please enter your password.");
PW2 = enter.nextLine();
if (ID.equals(ID2) && (PW.equals(PW2))) {
System.out.println("Welcome...");
} else if (!(ID.equals(ID2)) && ((PW.equals(PW2)))) {
System.out.println("Try again!");
} else if ((ID.equals(ID2)) && (!(PW.equals(PW2)))) {
System.out.println("Try again!");
} else if (!(ID.equals(ID2)) && !((PW.equals(PW2)))) {
System.out.println("Try again!");
}
if (entry == 3) {
System.out.println("**Your account has been blocked**");
break;
}
} while (!(ID.equals(ID2)) && !((PW.equals(PW2))));
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.