我想测试用户是否提交了合理的数据,后来将其格式化为整数。 switch语句的问题在哪里? :)Swtich语句语法错误
void convert(String str)
{
int i=0;
String x=str.startsWith();
switch (x) {
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
case 9:
case 0:
int i = Integer.parseInt(str);
break;
default:
System.out.println ("Should start with fixnumber");
}
System.out.println (i);
}
你变量是一个字符串,看看您的测试,如果它是一个int?你也没有告诉我们这种行为。你看到任何错误?如果是这样,什么? –