public class Test4 {
//static float i=;
public static void main(String[] args){
for(int i=0;i<3;i++){
switch(i){
case 0:break;
case 1:System.out.println("one");
case 2:System.out.println("two");
case 3:System.out.println("three");
}
}
System.out.println("done");
}}
这个结果为什么是:one,two,three,two,three,done;
请帮我解释一下,谢谢!
//static float i=;
public static void main(String[] args){
for(int i=0;i<3;i++){
switch(i){
case 0:break;
case 1:System.out.println("one");
case 2:System.out.println("two");
case 3:System.out.println("three");
}
}
System.out.println("done");
}}
这个结果为什么是:one,two,three,two,three,done;
请帮我解释一下,谢谢!
//static float i=;
public static void main(String[] args){
for(int i=0;i<3;i++){
switch(i){
case 0:break;
case 1:System.out.println("one");break;
case 2:System.out.println("two");break;
case 3:System.out.println("three");break;
}
}
System.out.println("done");
}}
for (int i = 0; i < 3; i++) {
switch (i) {
case 0:
break;
case 1:{
System.out.println("one");
break;
}
case 2:{
System.out.println("two");
break;
}
case 3:{
System.out.println("three");
break;
}
} }
System.out.println("done");
case 0:
break;
case 1:
System.out.println("one");
break;
case 2:
System.out.println("two");
break;
case 3:
System.out.println("three");
break;
}
就是没写break的问题
case 1:System.out.println("one");break;
case 2:System.out.println("two");break;
case 3:System.out.println("three");break;
没有break,继续往下运行c
case 1: xxx(); break;
case 2: yyy();
case 3: zzz(); break;
default: foo();
}等价于goto labelx; //此处是x的值,比如goto label1;
goto _default;
label1:
xxx(); goto end;
label2:
yyy();
label3:
zzz(); goto end;
_default:
foo();
end:
switch(条件)
{
case 条件 :语句 ; break;//跳出整个语句块继续去判断下一个
.
.
.
.
.
}