没有输出任何结果
输出结果为3
输出结果是3和4
输出结果是1、3和4
第1题:
有以下程序: #include<stdio.h> main() { int x=1,y=0,a=0,b=0; switch(x) { case 1: switch(y) { case 0:a++;break; case 1: b++;break; } case 2:a++;b++;break; case 3:a++;b++; } printf("a=%d,b=%d\n",a,B); } 程序的运行结果是( )。
A.a=1,b=0
B.a=2,b=2
C.a=1,b=1
D.a=2,b=1
第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题:
以下代码的输出结果是什么? 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.编译错误
第4题:
A. switch(x){case 1.0:printf("*\n"); case 2.0:printf("*\n"); }
B. switch(a){case 1:printf("*\n");case 2:printf("*\n"); }
C. switch(a+b) {case 1:printf("*\n"); case 1+2:printf("*\n"); }
D. switch(a+b);{case 1:printf("*\n");case 2:printf("*\n"); }
第5题:
编译和执行以下代码,输出结果是( )。 int i=1; switch (i) { case 0: System.out.print("zero,"); break; case 1: System.out.print("one,"); case 2: System.out.print("two,"); default: System.out.println("default"); }
A.one,
B.one,two,
C.one,two,default
D.default
第6题:
给出下列代码段: public class ex38 { public static void main (String args [ ] ) { int m; switch(m) { case 0: System.out.println ( "case 0" ); case 1:System.out.println("case 1");break; case 2: default: System.out.print in ("default") } } 下列m的______值将引起"default"的输出。
A.0
B.1
C.2
D.以上答案都不正确
第7题:
有下列程序: #include <stdio.h> main() { int x=1,y=0,a=0,b=0; switch(x) { case 1: switch(y) { case 0:a++;break; case 1:b++;break; } case 2: a++;b++;break; case 3: a++;b++; } printf("a=%d,b=%d\n",a,B) ; } 程序的运行结果是( )。
A.a=1,b=0
B.a=2,b=2
C.a=1,b=1
D.a=2,b=1
第8题:
若有以下定义,则正确的switch语句是______。float x;int a,b;
A.switch(x) { case 1.0:printf("*\n"); csse 2.0:printf("**\n"); }
B.switch(x) { case 1,2:printf("*\n"); case 3:printf("**\n"); }
C.switch(a+b) { case 1:printf("\n"); case 1+2:printf("**\n"); }
D.switch(a+b); { case 1:printf("*\n"); case 2:printf("**\n"); }
第9题:
给出下列的程序片段,m为( )时将会输出default。 switch (m) case ():Systemt.out.println("case 0"); case 1: System.out.println("case 1");break; case 2:System.out.println("case2");break; default:System.out.println("default");
A.0
B.1
C.2 2
D.3
第10题:
若有以下定义:float x;int a,b,c=2;,则正确的switch语句是( )
A.switch(x) { case 1.0:printf("*\n"); case 2.0:printf("**\n"); }
B.switch(int(x)) { case 1:printf("*\n"); case 2:printf("**\n"); }
C.switch(a+b) { case 1:printf("*\n"); case 1+2:printf("**\n"); }
D.switch(a+B){ case 1:printf("*\n"); case c:printf("**\n"); }
第11题:
有如下代码段:
switch ( x ){
case 1:System.out.println("One");break;
case 2:
case 3:System.out.println("Two");break;
default:System.out.println("end");
}
变量x的取值下列哪些情形时,能使程序输出"Two" 。
A. 1
B. 2
C. 3
D. default
第12题:
class TestApp{ public static void main(String[] args){ int x = 5; switch(x){ case 1: case 2: case 3: System.out.println(“一季度”); break; case 4: case 5: case 6: System.out.println(“二季度”); case 7: case 8: case 9: System.out.println(“三季度”); break; ase 10: case 11: ase 12: System.out.println(“四季度”); break; default: System.out.println(“不是有效的月份”); } } } 上述程序运行后的结果是哪项?()
第13题:
下面的方法,当输入为2的时候返回值是多少?( )
public int getValue(int i) {
int result = 0;
switch (i) {
case 1:
result = result + i;
case 2:
result = result + i * 2;
case 3:
result = result + i * 3; }
return result; }
答案:10
当i=2 case 1 不成立 case 2 时 result = 0 + 2 * 2 result = result + i * 2;后面你没有写break; 所以result = result + i * 2;执行结束后不会停止接着执行 result = 4 + 2 * 3
第14题:
以下程序段的运行结果是( )。 include<stdio.h> main() {int x=2,y=1: switch(x) {case 1: switch(y) {case 0:printf("x=2,y=1\n");break; case 1:printf("y=1\n");break; } case 2:printf("x=2\n"); } }
第15题:
若有以下定义,则正确的swish语句是______。 float x;int a,b;
A.switch(x) {case 1.0:printf("*\n"); case 2.0:printf("**\n"); }
B.switch(x) {case 1,2:printf("*\n"); case 3:printf("**\n"); }
C.switch(a+b) {case 1:printf("\n"); case 1+2:printf("**\n"); }
D.switch(a+b); {case 1:printf("*\n"); case 2:printf("**\n"); }
第16题:
若a,b,c1,c2,x,y均是整型变量,正确的switch语句是______。
A.switch(a+b); {case 1:y=a+b;break; case 0:y=a-b;break; }
B.switch(a*a+b*b) {case 3; case 1:y=a+b;break; case 3:y=b-a;break; }
C.switch a {case c1:y=a-b;break; case c2;x=a*b;break; default:x=a+b; }
D.switch(a-b) {default:y=a*b;break; case 3:case 4:x=a+b;break; case 10:case11:y=a-b;break; }
第17题:
给出下面代码片段: public class Test{ public static void main (String args[ ]){ int m; switch(m) { case 0:System.out.println("case 0"); case 1:System.out.println("case 1"):break; case 2: default:System.out.println("default"); } } } 下列m的( )值将引起"default"的输出。
A.1
B.2
C.4
D.0
第18题:
执行如下程序: public class Test { public static void main (String args[]) { int x=1,a=0,b=0; switch (x) { case 0: b++; case 1: a++; case 2: a++;b++; } System.out.println("a=" +a ",b=" +b); } } 该程序的输出结果是( )。
A.a=2,b=1
B.a=1,b=1
C.a=1,b=0
D.a=2,b=2
第19题:
给出下列的程序段,m为何值时将会输出default? ( ) switch(m) { case 0: System.out.println("case 0"); case 1:System.out.println("case 1");break; case 2:System.out.println("case 2");break; default:System.out.println("default"); }
A.0
B.1
C.2
D.3
第20题:
若有定义float x=1.5;int a=1,b=3,c=2;,则正确的switch语句是
A.swimh(x) {case 1.0:printf("*\n"); case 2.0:printf("**\n");}
B.switch((int)x); {case 1:printf("*\n"); case 2:printf("**\n");}
C.switch(a+
D. {case 1:pfintf("*\n"); case 2+1:pfintf("**\n");}switch(a-I-{case 1:pfintf("*\n"); case c:printf("**\n");}
第21题:
给出下列的程序代码片段,m为哪个值时将会输出default? switch(m) { case 0:System.out.println("case0"); case 1:System.out.println("case 1");break; case 2:System.out.println("case 2");break; default:System.out.println("default"); }
A.0
B.1
C.2
D.3
第22题:
若定义:float x;int a,b;,则正确的switch语句是( )。
A.switch(x) { case1.0:cout<<"*\n"; case2.0:cout<<"**\n";
B.switch(x) { case 1.2:cout<<"*\n"; case 3:cout<<"**\n"; }
C.switch(a+b) { case 1.0:cout<<"*\n"; case 1+2:cout<<"**\n ";
D.switch(a+b) { case 1:cout<<"*\n"; case 2:cout<<"**\n";
第23题:
研究下面的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时,运行结果是()。