有没有更有效的方法在菜单中创建子菜单

disho6za  于 2021-07-09  发布在  Java
关注(0)|答案(0)|浏览(176)

我正在学习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();
            }
        }
    }
}

这就是我目前所做的(但还有很多选择)

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题