我想为一个简单的数学游戏创建一个用户选择菜单:
=============================
Create a New User [1]
Continue as Existing User [2]
Exit [3]
=============================
当用户选择[1]时,游戏将开始,当用户选择[2]时,将显示用户列表,如下所示:
=============================
Select User to Continue As
John [1]
Rob [2]
Steve [3]
Back Button [0]
=============================
我怎么能做这样的事情?
- 打印用户说明(如:
System.out.println("Create a New User [1] ")
) - 从控制台获取用户输入(
Scanner in = new Scanner(System.in); int menuItem = scan.nextInt();
) - 比较用户输入与可能情况(
switch (menuItem):{case 1: //do your code; break; case 2: //do your code; break;}
)
//add code to accept choice
System.out.println("n============================="+"nCreate a New
User [1]"+
"nContinue as Existing User [2]"+"nExit
[3]"+"n=============================");
switch(choice){
case 1:
//call method to create user;
break;
case 2:
//call method to conitnue as existing user
existingUser();
break;
case 3:
//call method to exit
break;
}