简体   繁体   English

为什么我没有跳出循环? 即使我的输入是正确的

[英]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.

相关问题 为什么即使我的文件位于正确的位置,我也会收到 filenotfound 异常? - Why am I getting a filenotfound exception even though my file is there in the correct location? 为什么我的for循环出现此错误? - Why am I getting this error with my for loop? 为什么我输入无效无限循环? - Why am I getting an input Invalid Infinite Loop? 为什么我的 Scanner 输入行出现错误? - Why am I getting an error here in my Scanner input line? 为什么我在分别打印偶数和奇数索引字符的问题中没有得到正确的输出? - Why am I not getting the correct output in ques of printing even and odd index character seperatly? 为什么我会收到此代码的 NoSuchElementException? Java给用户第二次正确输入机会的方法 - Why am I getting NoSuchElementException for this code? Java method for giving users a second chance for correct input 为什么即使我在proguard-project.txt中添加了jar文件,也出现此错误? - Why i am getting this errors even i have added my jar files in proguard-project.txt? 为什么会出现此“越界”错误? - Why am I getting this “Out of Bounds” error? 为什么我出现内存不足错误 - Why am I getting an out of Memory error 为什么我使索引超出范围? - Why am I getting Index out of bounds?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM