切换语句问题

时间:2014-10-10 02:10:33

标签: java switch-statement

我的切换声明有问题,对不起,如果这是微不足道的,我很新!在切换语句中我收到错误:

  

令牌上的语法错误,而不是标签。

在我收到错误的每个案例中:

  

令牌上的语法错误"案例",断言预期

productNumbernumberOfProduct都是用户输入的int类型。 totalcurrentTotal的类型为double

Switch (productNumber) //problem occurs here, at the switch statement and at each case
{
    case 1:
        currentTotal = numberOfProduct * 2.98;
        total += currentTotal;
        break;

    case 2:
        currentTotal = numberOfProduct * 4.50;
        total += currentTotal;
        break;

    case 3:
        currentTotal = numberOfProduct * 9.98;
        total += currentTotal;
        break;

    case 4://
        currentTotal = numberOfProduct * 4.49;
        total += currentTotal;
        break;

    case 5:
        currentTotal = numberOfProduct * 6.87;
        total += currentTotal;
        break;

    default:
        System.out.println("The number entered is not a known product number. Known product numbers are 1, 2, 3, 4, and 5.");
        --count;
}

2 个答案:

答案 0 :(得分:0)

这是语法错误。 switch需要小写。

答案 1 :(得分:0)

开关 - >切换?你可以尝试一下