[英]Why I am not getting out of loop? Even My input is correct
public void getLogin()throws IOException{ int x=1; public void getLogin() 抛出 IOException{ int x=1;
do {
try {
data.put(961668 , 2255);
data.put(961768 , 2253);
data.put(961568 , 2353);
System.out.println("----------Welcome to the ATM Machine Project----------");
System.out.println("Enter your Account number: ");
setAccountNumber(menuOutput.nextInt());
System.out.println("Enter your correct PIN number: ");
setPinNumber(menuOutput.nextInt());
}catch (Exception e) {
System.out.println("\n"+"You have Enter Incorrect value !! you have to enter only numbers: "+"\n");
x=2;
}
for(Entry<Integer, Integer> entry : data.entrySet()) {
if(entry.getKey()== getAccountNumber() && entry.getValue()== getPinNumber()) {
getAccountType();
}
}
System.out.println("\n"+"Wrong Account or Pin Number "+"\n");
}while(x == 1);
}
Is there any reason, performance or otherwise, to prefer one over the other?是否有任何理由、性能或其他原因偏爱其中一个? Where am I doing Mistake?我在哪里做错了? I check every thing.我检查每一件事。
The do loop executes as long as the value of x is 1. Which in your case is not changed even when the desired result is achieved.只要 x 的值为 1,do 循环就会执行。在您的情况下,即使达到所需的结果也不会改变。
May be try updating the value of x to some other value except 1 in valid scenario as well.在有效场景中也可以尝试将 x 的值更新为 1 以外的其他值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.