2017-07-03 92 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 ... 
相关问题