51

Java中的switch-12212886-51CTO博客

 6 years ago
source link: http://blog.51cto.com/12222886/2067557
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
switch语句的作用其实就相当于if()else,就是一种选择语句,语法如下:switch(表达式){case常量表达式1:语句1;case常量表达式2:语句2;…case常量表达式n:语句n;default:语句n+1;}需要注意的是switch中表达式的类型可以是byte,short,char,int,enum类型,java7之后可以使string类型也支持作为表达式,可以研究下原理:pub

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK