1. 程式人生 > >switch… case 語句的用法

switch… case 語句的用法

[] other sta rgs bsp str 復制代碼 ring 表達

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 語句的用法