2015-10-19 110 views
0

boolean test = true; //我的循環從這裏開始,我希望能夠在非事件被選中時循環// switch語句,我希望循環在顯示錯誤消息後返回到case 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; 
} 
+0

'proceed'的值是多少? – naomi

+0

Proceed = Next.nextInt(); –

回答

0

如果你想送它回到1的情況下,那麼你需要進行設置爲1。我猜Next.nextInt()會給你1,2,但隨後3,然後4,等等。超過2的任何內容都會默認爲

+0

不要得到它,所以我完全刪除循環,並設置進行到1?繼續= Next.nextInt(); –

+0

嘗試放置一個調試語句,以便您可以看到正在設置的繼續 – naomi