java - 在菜单中创建子菜单是否有更有效的方法
问题描述
我现在正在学习java,我想知道是否有一种更简单的方法可以在菜单中创建子菜单,而无需将菜单硬编码到这个项目中。
System.out.println("Enter one of the following commands:");
System.out.println("1 - List todos");
System.out.println("2 - Add todo");
Scanner scanchoice = new Scanner(System.in);
System.out.println();
System.out.println("Enter \"1\", \"2\" ,\"3\", \"4\" or \"5\"");
int choiceentry = scanchoice.nextInt();
while (choiceentry != 5) {
if (choiceentry < 1 || choiceentry > 5) {
System.out.println("Enter \"1\", \"2\", \"3\", \"4\"or \"5\"");
choiceentry = scanchoice.nextInt();
} else if (choiceentry == 2) {
Scanner EnterCategory = new Scanner(System.in);
System.out.println("Select an Item to between 1 and 6 ");
System.out.println("Enter one of the following commands:");
System.out.println("1 - Red");
System.out.println("2 - White");
System.out.println("3 - Blue");
Scanner Colorchoice = new Scanner(System.in);
System.out.println();
System.out.println("Enter \"1\", \"2\" or \"3\"");
String ColorChoiceEntry = Colorchoice.next();
while (ColorChoiceEntry != 3) {
if (ColorChoiceEntry < 1 || ColorChoiceEntry > 6) {
System.out.println("Enter \"1\", \"2\", \"3\",\"4\" ,\"5\"or \"6\"");
choiceentry = scanchoice.nextInt();
} else if (choiceentry == 1) {
SystemColor.getColor(ColorChoiceEntry).getRed();
} else if (choiceentry == 2) {
//..something else
SystemColor.getColor(ColorChoiceEntry).getWhite();
}
}
}
}
这是我到目前为止所做的(但有更多选择
解决方案
推荐阅读
- java - why JVM Current old generation capacity + new generation capacity+Metaspace capacity not equals physical memory
- angular - 未捕获(承诺):错误:模板解析错误:无法绑定到“上传器”,因为它不是“输入”的已知属性
- r - 闪亮的应用地图未正确连接到单选按钮
- neo4j - 将一个标签的“属性键”合并到另一个标签中
- jpa - 集成 Java EE 7、Spring Security 和 EclipseLink 的问题
- amazon-web-services - 在 AWS RHEL 7.6 实例上安装 SCL
- c++ - 多线程 Monte Carlo pi 计算会因更多线程而失去精度?
- odoo - Odoo 11 工人
- python - 如何将列表的元素作为 np.where() 中的条件?
- java - 在 Spring Boot jar 中解压球衣库