我写了这段代码,但似乎没有用。当我们键入d时,它将对美元进行计算,但仍在进行(..做什么?)。

您能在列表部分看到+检测+吗,那是错误的部分?

String currency = sc.next();
        char detect = currency.charAt(0);
switch (detect){
    case 'D':
    case 'd':
        double dollar = (amount/18*10);
        System.out.println(amount + " Turkish Lira(s) --> " + dollar + " Dollar");

    case 'E':
    case 'e':
        double euro = (amount/23*10);
        System.out.println(amount + " --> " + euro + " Euro");

    case 'T':
    case 't':
        double lira = (amount);
        System.out.println(amount + " --> " + lira+ " Lira(s)");

        while (detect!='d'|| detect!='e' || detect!='t' || detect!='D'|| detect!='E' || detect!='T'){
            System.out.println("Can u See " + detect + " In The List ?\n" + menucur);
            currency = sc.next();
            detect = currency.charAt(0);
            }
    }

最佳答案

您需要在每种情况的末尾为switch语句添加break

http://docs.oracle.com/javase/tutorial/java/nutsandbolts/switch.html

09-11 12:51