switch后面只能带可以自动转换为整形(包括整形)的类型,不能为实型。
具体如下:
C/C++中:
支持类型:byte,char,short,int,long,bool,枚举类型。
不支持的类型:float,double,string
Java中:
A switch works with the byte, short, char, and int primitive data types. It also works with enumerated types (discussed in Enum Types), the String class, and a few special classes that wrap certain primitive types: Character, Byte, Short, and Integer (discussed in Numbers and Strings).
出处.