我在哪里错了这个菜单

我已经为硬币计数器的菜单系统创建了代码,我正在尝试使它成为可能,以便用户在选择第一个选项之后可以选择多个选项,直到决定结束程序为止。它不会循环,并且代码仅运行一个选项,然后我必须通过在eclipse上运行来手动重新启动代码。任何人都可以让我对我在这里错过的事情有所了解,谢谢:)

Scanner ss=new Scanner(System.in);
int Choice;
int opt;
    System.out.println("***Coin Sorter - Main Menu***");
    System.out.println("    1 - Coin Calculator");
    System.out.println("    2 - Multiple coin calculator");
    System.out.println("    3 - Print Coin list");
    System.out.println("    4 - Set details");
    System.out.println("    5 - Display program configurations");
    System.out.println("    6 - Quit the program");
    Choice=ss.nextInt();
    switch(Choice) {
        case 1: coinCalculator();
                break;
        case 2: multiCoinCalculator();
                break;
        case 3: printCoinList();
                break;
        case 4: System.out.println("***Set Details Sub-Menu***");
                System.out.println("1 - Set currency");
                System.out.println("2 - Set minimum coin input value");
                System.out.println("3 - Set maximum coin input value");
                System.out.println("4 - Return to main menu");
                opt=ss.nextInt();
                if (opt==1) {
                setCurrency(Currency);
                }else if (opt==2) {
                    setMinCoinin(opt);
                }else if (opt==3) {
                    setMaxCoinin(opt);
                }else if (opt==4);
                    CoinSorter();
                break;
        case 5: displayProgramConfigs();
                break;
        case 6: if(Choice != 6) System.out.println("Unkown option");    
    } while (Choice !=6);
阿文德·库玛·阿维纳什(Arvind Kumar Avinash)
  1. 使用defaultUnkown option从教程switch语句中了解更多信息
  2. 将菜单do-while正确放入循环中。您错过do了代码。
  3. 你已经错误地把;else if (opt==4)

最后但并非最不重要的一点是,请始终遵循Java命名约定,例如,变量名称可以为,choice但不应为Choice

演示:

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner ss = new Scanner(System.in);
        int choice;
        int opt;
        do {
            System.out.println("***Coin Sorter - Main Menu***");
            System.out.println("    1 - Coin Calculator");
            System.out.println("    2 - Multiple coin calculator");
            System.out.println("    3 - Print Coin list");
            System.out.println("    4 - Set details");
            System.out.println("    5 - Display program configurations");
            System.out.println("    6 - Quit the program");
            choice = ss.nextInt();
            switch (choice) {
            case 1:
                coinCalculator();
                break;
            case 2:
                multiCoinCalculator();
                break;
            case 3:
                printCoinList();
                break;
            case 4:
                System.out.println("***Set Details Sub-Menu***");
                System.out.println("1 - Set currency");
                System.out.println("2 - Set minimum coin input value");
                System.out.println("3 - Set maximum coin input value");
                System.out.println("4 - Return to main menu");
                opt = ss.nextInt();
                if (opt == 1) {
                    setCurrency(Currency);
                } else if (opt == 2) {
                    setMinCoinin(opt);
                } else if (opt == 3) {
                    setMaxCoinin(opt);
                } else if (opt == 4) {
                    CoinSorter();
                }
                break;
            case 5:
                displayProgramConfigs();
                break;
            case 6:
                System.out.println("Good Bye!");
                break;
            default:
                System.out.println("Unkown option");
            }
        } while (choice != 6);
    }
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

寻找价值在哪里我错了?

Java:方法;我在哪里做错了?

谁能看到我这个 srcset 哪里出错了?

我在这个堆栈操作中哪里出错了?

我在哪里做错了/做和陈述

使用Intrinsics,Add + Mul的速度变慢-我在哪里错了?

读者-C语言的作家-我在哪里错了?

使用C#的Laplace我在哪里出错了?

寻找素数,我在哪里弄错了?

这个自定义React钩子在哪里出错了-useLocalStorage?

我的推理哪里错了?

我哪里错了?

我哪里出错了?

这个元素在哪里?

我应该在哪里捕捉这个Promise MongoError?

我在这个 SPARQL 查询中的错误在哪里?

jQuery onDropdownShown中未定义键警报。我不确定我在哪里做错了

我想创建一个可清除的搜索字段。我在哪里弄错了?

我在这个用于功率查询的 M-Code 函数中哪里出错了?

ng-class不起作用。我在哪里做错了?

批处理文件/ wait不起作用,我在哪里做错了?

我在哪里做错了什么?执行时出错(运行时错误)

当从另一个类引用时,列表变为空,我在哪里做错了?

我哪里弄错了?

我哪里出错了 - JAVASCRIPT

这个Oracle对象在哪里?

Ubuntu:“可编辑菜单加速器”(基于每个应用程序)。这个选项在哪里?

我想用相同但使用reduce完成的forEach函数替换这个函数。你能说我哪里做错了吗?

这个程序是用 C 编写的,我想知道我哪里出错了。尝试打印 'meow' 3 次