【问题标题】:Switch statement problems切换语句问题
【发布时间】:2014-10-10 02:10:32
【问题描述】:

我的 switch 语句有问题,对不起,如果这是微不足道的,我是新手!在 switch 语句中我得到了错误:

标记的语法错误,应改为标签。

在每种情况下,我都会遇到错误:

令牌“case”的语法错误,断言预期

productNumbernumberOfProduct 都是用户输入的 int 类型。 totalcurrentTotaldouble 类型。

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;
}

【问题讨论】:

  • 什么编程语言?如果是Java的话,Switch应该是switch,以小写字母开头。
  • 它是 Java,它解决了我所有的问题......哈哈。万分感谢。简直不敢相信这么简单……

标签: java switch-statement


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    开关->开关?你可以试试

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多