我得到了这个错误:
错误:期望一个标识符,但得到':'。尝试在':'之前插入标识符。
在尝试使用switch-case时,我不知道我的代码出了什么问题
void main() {
int day = 5;
switch (day) {
case : 1 {
print("Monday");
}
break;
case : 2 {
print("Tuesday");
}
break;
case : 3 {
print("Wednesday");
}
break;
case : 4 {
print("Thursday");
}
break;
case : 5 {
print("Friday");
}
break;
case : 6 {
print("Saturday");
}
break;
case : 7 {
print("Sunday");
}
break;
default : {
print("There is no day like this");
}
break;
}
}
冒号必须在值
之后void main() {
int day = 5;
switch (day) {
case 1:
{
print("Monday");
}
break;
case 2:
{
print("Tuesday");
}
break;
case 3:
{
print("Wednesday");
}
break;
case 4:
{
print("Thursday");
}
break;
case 5:
{
print("Friday");
}
break;
case 6:
{
print("Saturday");
}
break;
case 7:
{
print("Sunday");
}
break;
default:
{
print("There is no day like this");
}
break;
}
}