【发布时间】:2014-10-10 02:10:32
【问题描述】:
我的 switch 语句有问题,对不起,如果这是微不足道的,我是新手!在 switch 语句中我得到了错误:
标记的语法错误,应改为标签。
在每种情况下,我都会遇到错误:
令牌“case”的语法错误,断言预期
productNumber 和 numberOfProduct 都是用户输入的 int 类型。 total 和 currentTotal 是 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;
}
【问题讨论】:
-
什么编程语言?如果是Java的话,
Switch应该是switch,以小写字母开头。 -
它是 Java,它解决了我所有的问题......哈哈。万分感谢。简直不敢相信这么简单……
标签: java switch-statement