2017-07-03 79 views
0
Scanner scn =new Scanner(System.in); 
int Choice = scn.nextInt(); 

do 
{ 
// Display Menu 
System.out.println("*** MENU ***"); 
System.out.println("1. Register Member"); 
System.out.println("2. Rent Books"); 
System.out.println("3. View Member and Rental Information"); 
System.out.println("4. Exit"); 

     switch(Choice) 
     { 
      case 1 : { 
         System.out.println("M"); 
        }break; 
      case 2 : { 
         System.out.println("\n\n2. View All Students & Marks");        
        }break; 
      case 3 : { 
         System.out.println("\n\n3. Search for Student"); 
        }break; 
      case 4 : { 
         System.out.println("choice4"); 
        }break;     
      default :{ 
         System.err.println("\nInvalid Menu Option"); 
        }break; 
      }   
    }while(Choice !=4); 
    } 
} 

它的輸出將返回空白,並且當按下一個數字時它將會永久循環我嘗試安排空格的輪廓很多次,但仍然沒有工作我是試圖使菜單不會退出,除非用戶選擇4執行其他選擇,並且一旦執行了其他功能就重新顯示菜單。我的菜單由於某種原因不能正常工作

+0

您輸入的int _before_你的循環,然後循環,直到你的int是4,但沒有在你的循環變化的值的int,所以如果它不是4,它將永遠不會是4.考慮如何輸入int _inside_你的循環。 – khelwood

+0

無關:A)格式化問題 - 不要將這樣的代碼亂七八糟在我們B)名稱問題 - 閱讀關於Java命名約定並遵循它們。變量go camelCase! – GhostCat

回答

0

簡單:你需要用戶輸入以外的你的循環。

此舉掃描儀要求循環,如:

int choice; 

do { 
... print the menu 
choice = scn.nextInt(); 
switch(choice) 
} while ... 
相關問題