2008年12月3日 星期三

simple java(五)---switch

switch without break

public class SwitchNoBreak
{
public static void main( String s[] ) {
char ch = 'a';
int x = 0;
switch ( ch )
{
case 'a':
x = 10;
case 'b':
x = 20;
case 'c':
x = 30;}
System.out.println( "x = " + x );}}
******************
switch with break
public class SwitchWithBreak
{public static void main(String s[])
{
char ch = 'a';
int x = 0;
switch ( ch ) {
case 'a':
x = 10;
break;
case 'b':
x = 20;
break;
case 'c':
x = 30;
break;}
System.out.println( "x = " + x );}}

沒有留言: