首页 > 代码库 > switch… case 语句的用法

switch… case 语句的用法

public class Test7
{
     public static void main(String[] args)
     {
        int i=5;
        switch(i)
        {
              case 1:
               System.out.println("one");
              case 10:
               System.out.println("ten");
              case 5:
               System.out.println("five");   
              case 3:
               System.out.println("three");
              default:
               System.out.println("other");
        }
    }
}
复制代码
è 结果是:

five
three
other
 
复制代码
switch(表达式)

{

case 常量表达式1:语句1;

....

case 常量表达式2:语句2;

default:语句;

}

switch… case 语句的用法