switch 语句的参数类型

switch(参数值){

    case value:

    [default://可选

    defaultStatements;

]

参数值类型必须是这几种类型之一:int,byte,char,short

switch为什么只能用int,short,byte,char,而不能用long,String呢?因为switch 只能使用 int 类型或者是可以转换为 int类型的参数(char,char 和 int 通过ascii转换)。

原文地址:https://www.cnblogs.com/zhouwenJS/p/3866151.html