没有输出任何结果
输出结果为3
输出结果是3和4
输出结果是1、3和4
第1题:
若有定义:float x=1.5;int a=1,b=3,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 2+1:printf("**\n");}
D.switch(a+B) {case 1:printf("*\n"); case c:printf("**\n");}
第2题:
有以下程序: #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
第3题:
若有定义 : float x=1.5; int a=1,b=3,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 2+1: printf("**\n");}
D)
switch(a+b)
{ case 1: printf("*\n");
case c: printf("**\n");}
第4题:
以下代码的输出结果是什么? 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.编译错误
第5题:
已知如下代码: 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
第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题:
下面的方法,当输入为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
第8题:
A.没有输出任何结果
B.输出结果为3
C.输出结果是3和4
D.输出结果是1、3和4
第9题:
以下程序段的运行结果是( )。 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"); } }
第10题:
若有以下定义,则正确的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"); }