我的循环保持循环也循环错误的东西?

时间:2015-10-19 12:38:12

标签: eclipse loops while-loop switch-statement boolean

boolean test = true; //我的循环从这里开始,我希望能够在选择非案例时循环// switch语句,我希望循环在显示错误后返回到案例1消息。

while (test)

Proceed = Next.nextInt();
switch (Proceed) {

    case 1:// Proceed 
        System.out.println("Please enter your 5 digit pin below.");
        Scanner Pin = new Scanner(System.in);
        int Pincode = Pin.nextInt();
        if (Pincode > 9999 && Pincode < 99999) {
            System.out.println("1)Display Balance");
            System.out.println("2)Withdraw Cash");
            System.out.println("3)Other services");

        } else {
         System.err
                    .println("Sorry,the pin you enterd was incorrect\nyour card is being ejected\nPlease wait...");
        }
        test=false;
        break;

    case 2:// Return Card
        System.err.println("Your card is being ejected.\n Please Wait..");
        test=false;
        break;

    default:  // i want to display this message and send it back to case 1. when i do the method i'm doing it just keeps spamming this message.
        System.err.println("Sorry your request could not be processed.Please re-try");
        test=true;
}

1 个答案:

答案 0 :(得分:0)

如果你想把它发回到案例1那么你需要设置继续到1.我猜测Next.nextInt()会给你1,2,然后是3然后是4,等等。 2将转到默认情况