2014-10-10 110 views
0

我的開關語句有問題,對不起,如果這很瑣碎,我很新!在switch語句中,我得到錯誤:開關語句問題

令牌的語法錯誤,標籤預期代替。

在每一個我遇到了錯誤的情況:

令牌「案例」

語法錯誤,斷言預期

兩個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; 
} 
+0

什麼編程語言?如果是Java,那麼'Switch'應該是一個以小寫字母開頭的'switch'。 – Tiny 2014-10-10 02:14:30

+0

這是Java,解決了我所有的問題......哈哈。萬分感謝。簡直難以置信...... – 2014-10-10 02:15:48

回答

0

這是一個語法錯誤。 switch需要小寫。

+0

解決了它,感謝您的幫助! – 2014-10-10 02:26:43