研究下面的Java代码: switch (x) { case 1: System.out.println(1); case 2: case 3: System.out.println(3); case 4: System.out.println(4); } 当x=2时,运行结果是()。
第1题:
下列程序的输出结果是______。 main() { int i=3; switch(i) { case 1: case 2:printf("%d",i); case 3: case 4:break; default:printf("OK"); } }
A.0
B.3
C.OK
D.没有任何输出
第2题:
已知如下代码: switch(m) { case 0: System.out.println("Condition0"); case 1: System.out.println("Condition 1"); case 2: System.out.println("Condition 2"); case 3: System.out.println("Condition 3"); break; default: System.out.println("Other cCndition"); } 当m为( )时,"Condition 2"会出现在输出结果中。
A.2
B.0、1
C.0、1、2
D.0、1、2、3
第3题:
A.没有输出任何结果
B.输出结果为3
C.输出结果是3和4
D.输出结果是1、3、4
第4题:
程序:classTestApp{publicstaticvoidmain(String[]args){intX=5:switch(x){casel:case2:case3:System.out.println(一季度”);break;case4:case5:case6:System.out.println(二季度”);break;default:System.out.println(三季度以上”);break;}}}上述程序运行后的结果是哪项?()
A.一季度
B.二季度
C.三季度以上
D.无输出
第5题:
以下代码的输出结果是什么? class Foo{ public static void main(String args[]){ int x=4,j=0; switch(x){ case 1:j++; case 2:j++; case 3:j++; case 4:j++; case 5:j++; break; default:j++; } System.out.println(j); } }()
A.1
B.2
C.3
D.编译错误
第6题:
下面程序的输出结果是( )。 public class Sun { public static void main(String args[ ]) { int i = 1; switch (i) { case 0: System.out.println("zero"); break; case 1: System.out.println("one"); case 2; System.out.println("two"); default: System.out.println("default"); } } }
A.one
B.one,default
C.one,two,default
D.default
第7题:
下列程序的输出结果是( )。 #include<iostream.h> void main() {char*str=”12123434”; int x1=0,x2=0,x3=0,x4=0,i; for(i=0;str[i]!=’\0’;i++) switch(str[i]) {case’1’:x4++; case’2’:x3++; case’3’:x2++; case’4’:xl++; ) cout<<xl<<“,”<<x2<<
A.8,6,4,1
B.8,6,3,2
C.8,8,4,l
D.8,6,4,2
第8题:
A.没有输出任何结果
B.输出结果为3
C.输出结果是3和4
D.输出结果是1、3和4
第9题:
下列程序的输出结果是______。 main() { int i=3; switch(i) { case1: case2:printf("%d",i); case3: case4:break; default: printf ("OK"); } }
A.0
B.3
C.OK
D.没有任何输出
第10题:
如下程序的输出结果是______。 #include<stdio.h> main() { int x=1,a=3,b=4; switch(x) { case 0:a--; case 1:b--; case 2:a--;b--; } printf("a=%d,b=%d\n",a,b); }
A.a=2,b=2
B.a=3,b=3
C.a=1,b=2
D.a=3,b=2