niusouti.com

单选题int i = 1,j = -1;  switch (i) {  case 0, 1:j = 1;  case 2: j = 2;  default; j = 0;  }  System.out.println(“j=”+j);  What is the result?()Aj = -1Bj = 0Cj = 1Dj = 2ECompilation fails.

题目
单选题
int i = 1,j = -1;  switch (i) {  case 0, 1:j = 1;  case 2: j = 2;  default; j = 0;  }  System.out.println(“j=”+j);  What is the result?()
A

 j = -1

B

 j = 0

C

 j = 1

D

 j = 2

E

 Compilation fails.


相似考题
更多“int i = 1,j = -1;  switch (i) {  case 0, 1:j = 1;  case 2: j”相关问题
  • 第1题:

    以下程序的输出结果是【 】。include main() {int j,a[]={1,3,5,7,9,11,13,15},*P=a+5; f

    以下程序的输出结果是【 】。

    include <stdio.h>

    main()

    { int j,a[]={1,3,5,7,9,11,13,15},*P=a+5;

    for(j=3; j;j-)

    { switch(i)

    { case 1:

    case 2: printf("%d",*p++); break;

    case 3: printf("%d",* (-p));

    }

    }

    }


    正确答案:9911
    9911 解析:switch语句的一般格式如下:
    switch(表达式)
    {case 常量表达式 1:语句1
    case 常量表达式 2:语句2

    case 常量表达式 n:语句n
    default:语句n+1}
    switch语句在执行的先计算表达式的值,当表达式的值与某—个case后面的常量表达式的值相等时,就执行此case后面的语句系列。由于“case常量表达式”只是起语句标号作用,并不是在该处进行条件判断,所以当根据switch后面表达式的值找到匹配的入口标号时,就从此标号开始执行下去,不再进行判断,直到在执行某个case分支后,遇到break语句才会跳出switch结构,即终止switch语句的执行。
    本题定义并初始化了一个一维数组a,同时将指针变量p指向了a[5]的地址。在for循环中,首先j=3,执行case3后面的语句,由于--p是将p的地址前移一位,所以*(--p)的值为a[4]的值,即输出9;当j=2时,执行case2后面的语句。由于 *p++中++与*同优先级,结合方向为自右而左,因此它等价于*(p++),作用是先得到p指向的变量的值(即*p),然后再使p+1赋给p,所以j=2时先输出a[4]的值9,再使得p指向a[5]的地址;当j=1时,执行case1后面的语句,由于case1后面没有终业语句,所以继续执行case2后面的语句,此时*p的值即a[5]的值,所以输出11,然后p地址后移。故本程序的输出结果为9911。

  • 第2题:

    以下程序的输出结果是()。includevoid main(){int a(5),b(6),i(0),j(0);switch(a) {

    以下程序的输出结果是( )。 #include<iostream.h> void main() { int a(5),b(6),i(0),j(0); switch(a) { case 5:switch(b) { case 5:i++;break; case 6:j++;break; default:i++;j++; } case 6:i++; j++; break; default:i++;j++; } cout<<i<<","<<j<<endl; }

    A.1,2

    B.1,3

    C.2,2

    D.2,3


    正确答案:A

  • 第3题:

    publicclassTest{publicstaticvoidmain(StringArgs[]){inti=1,j=0;switch(i){case2:j+=6;case4:j+=1;default:j+=2;case0:j+=4;}System.out.println(j=”+j);}}Whatistheresult?()

    A.0

    B.2

    C.4

    D.6

    E.9

    F.13


    参考答案:D

  • 第4题:

    intI=1,j=0switch(i){case2:j+=6;case4:j+=1;default:j+=2;case0:j+=4;}Whatisthevalueofjatline16?()

    A.0

    B.1

    C.2

    D.4

    E.6


    参考答案:A, E

  • 第5题:

    运行下列程序时,若输入数据为“321”,则输出结果是( )。 main() {int num,i,j,k,s; scanf("%d",&num); if(num>99) s=3; else if(num>9) s=2; else s=1; i=num/100; j=(num-i*100)/10; k=(num-i*100-j*10); switch(s) {case 3:printf("%d%d%d\n",k,j,i); break; case 2:printf("%d%d\n",k,j); case 1:printf("%d\n",k); } }

    A.123

    B.1,2,3

    C.321

    D.3,2,1


    正确答案:A
    解析:本题考查if-else语句和switch语句。scan函数通过键盘读入nUm的值。因为num=321>99,所以s=3,i=3,i=2k=1。因为s=3,所以执行case 3,输出k,j,i的值,然后通过breed结束程序。

  • 第6题:

    下列程序的输出的结果是______。 public class exl6 { public static void main(String[] args) { int j=10; for(int i=0;i<3;i++) { j-=i+1; switch (j){ case 3: break; case 5: break; case 8: break; default: j=0;break; } } System,out.println(j); } }

    A.5

    B.3

    C.8

    D.0


    正确答案:D

  • 第7题:

    以下程序的运行结果为?

    class test {

    public static void main(String args[]) {

    int i,j=0;

    for(i=10;i<0;i--) { j++; }

    switch(j) {

    case (0) : j=j+1;

    case ( 1、 : j=j+2; break;

    case ( 2、: j=j+3; break;

    case (10) : j=j+10; break;

    default : break;

    }

    System.out.println(j);

    }

    }

    A. 0

    B. 1

    C. 2

    D. 3

    E. 10


    正确答案:D

  • 第8题:

    int I=1, j=0   switch(i) {   case 2:   j+=6;   case 4:   j+=1;    default:    j +=2;   case 0:   j +=4;   }   What is the value of j at line 16?()

    • A、 0
    • B、 1
    • C、 2
    • D、 4
    • E、 6

    正确答案:A,E

  • 第9题:

    public class SwitchTest {  public static void main(String[] args) {  System.out.println(“value = “ + switchIt(4));  }  public static int switchIt(int x) {  int j = 1;  switch (x) {  case 1: j++; case 2: j++;  case 3: j++;  case 4: j++;  case 5: j++;  default: j++;  }  return j + x; }  }  What is the result?()  

    • A、 value = 3
    • B、 value = 4
    • C、 value = 5
    • D、 value = 6
    • E、 value = 7
    • F、 value = 8

    正确答案:F

  • 第10题:

    int i = 1,j = -1;  switch (i) {  case 0, 1:j = 1;  case 2: j = 2;  default; j = 0;  }  System.out.println(“j=”+j);  What is the result?()  

    • A、 j = -1
    • B、 j = 0
    • C、 j = 1
    • D、 j = 2
    • E、 Compilation fails.

    正确答案:E

  • 第11题:

    单选题
    写出程序的运行结果。 #include main( ) { int i=0,j=0,k=0,m; for ( m=0;m<4;m++ ) switch ( m ) { case 0:i=m++; case 1:j=m++; case 2:k=m++; case 3:m++; } printf ("/n%d,%d,%d,%d",i,j,k,m); } 该程序的执行结果是()。
    A

    0,1,2,5

    B

    0,1,2,4

    C

    0,1,1,3

    D

    0,1,2,3


    正确答案: C
    解析: 暂无解析

  • 第12题:

    单选题
    public class Test {  public static void main(String Args[]) {  int i =1, j = 0;  switch(i) {  case 2: j +=6;  case 4: j +=1;  default: j +=2;  case 0: j +=4;  }  System.out.println(“j =” +j);  }  }  What is the result? ()
    A

     0

    B

     2

    C

     4

    D

     6

    E

     9

    F

     13


    正确答案: D
    解析: 暂无解析

  • 第13题:

    以下代码的输出结果是什么? 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.编译错误


    正确答案:B

  • 第14题:

    intI=1,j=02.3.switch(i){4.case2:5.j+=6;6.7.case4:8.j+=1;9.10.default:11.j+=2;12.13.case0:14.j+=4;15.}16.Whatisthevalueofjatline16?()

    A.0

    B.1

    C.2

    D.4

    E.6


    参考答案:A, E

  • 第15题:

    inti=1,j=-1;switch(i){case0,1:j=1;case2:j=2;default;j=0;}System.out.println(j=”+j);Whatistheresult?()

    A.j=-1

    B.j=0

    C.j=1

    D.j=2

    E.Compilationfails.


    参考答案:E

  • 第16题:

    已知C源程序如下: include include void reverse(char S[]){ int C,i,J; f

    已知C源程序如下:

    include<stdio. h>

    include<string. h>

    void reverse(char S[]){

    int C,i,J;

    for(i=0,j=strlen(s)-1;i<j;i++,j++){

    c=s[i];

    s[i]=s[j];

    s[j]=c;

    }

    }

    void getHex(int number,char s[]){

    int I;

    i=0;

    while(number>0){

    if(number%16<10)

    s[i++]=number%16+'0';

    else

    switch(number%16){

    case 10:s[i++]='A';break;

    case 11:s[i++]='B';break;

    case 12:s[i++]='C';break;

    case 13:s[i++]='D';break;

    case 14:s[i++]='E';break;

    case 15:s[i++]='F';break;

    default:printf("Error");break;

    }

    number/=16;

    }

    s[i]:'\o';

    reverse(s);

    }

    int main(){

    unsigned int number;

    int i=0:

    char s[50];

    printf("%s","please input number;\n");

    scanf("%d",&number):

    getHex(number,s);

    i=0;

    while(s[i])

    printf("%c",s[i++]);

    return 0;

    }

    画出程序中所有函数的控制流程图。


    正确答案:流程图
    流程图

  • 第17题:

    以下程序的输出结果是()。includemain(){int a[3][3]={0,1,2,0,1,2,0,1,2},i,j,s=1;for

    以下程序的输出结果是( )。 #include<stdio.h> main() {int a[3][3]={0,1,2,0,1,2,0,1,2},i,j,s=1; for(i=0;i<3;i++) for(j=i;j<=i;j++) s+=a[i][a[j][j]]; printf("%d\n",s); }

    A.3

    B.4

    C.1

    D.9


    正确答案:B
    解析:当外层循环为i时,内层循环i只能取j=i,所以s+=a[i][a[j][j]],其实就是s+=a[i][a[i][i]],当i=0时,s=s+a[0][a[01[0]]=s+a[0][0]=1,当i=1时,s=s+a[1][a[1][1]1=s+a[1][1]=1+1=2,当i=2时,s=s+a[2][a[2][2]]=s+a[2][2]=2+2=4。

  • 第18题:

    下列程序的输出结果是【】。 include void main() { inta(5),b(6),i(0)1j(0); switch(a

    下列程序的输出结果是【 】。

    include<iostream.h>

    void main()

    {

    inta(5),b(6),i(0)1j(0);

    switch(a)

    {

    case 5:switch(b)

    {

    case 5:i++;break;

    case 6:j++;break;

    defaun:i++;j++;

    }

    case 6:i++;

    j++;

    break;

    default:i++;j++;

    }

    cout<<i<<","<<j<<endl;

    }


    正确答案:12
    1,2

  • 第19题:

    写出程序的运行结果。 #include main( ) { int i=0,j=0,k=0,m; for ( m=0;m<4;m++ ) switch ( m ) { case 0:i=m++; case 1:j=m++; case 2:k=m++; case 3:m++; } printf ("/n%d,%d,%d,%d",i,j,k,m); } 该程序的执行结果是()。

    • A、0,1,2,5
    • B、0,1,2,4
    • C、0,1,1,3
    • D、0,1,2,3

    正确答案:A

  • 第20题:

    int i = 0, j = 1;  if ((i++ == 1) && (j++ == 2)) {  i = 42;  }  System.out.println(“i = “ + i + “, j = “ + j);   What is the result?()  

    • A、 i = 1, j = 2
    • B、 i = 1, j = 1
    • C、 i = 42, j = 2
    • D、 i = 42, j = 1
    • E、 Compilation fails.

    正确答案:B

  • 第21题:

    public class Test {  public static void main(String Args[]) {  int i =1, j = 0;  switch(i) {  case 2: j +=6;  case 4: j +=1;  default: j +=2;  case 0: j +=4;  }  System.out.println(“j =” +j);  }  }  What is the result? () 

    • A、 0
    • B、 2
    • C、 4
    • D、 6
    • E、 9
    • F、 13

    正确答案:D

  • 第22题:

    1. int I=1, j=0  2.    3. switch(i)  {  4. case 2:  5. j+=6;  6.    7. case 4:  8. j+=1;  9.    10. default:  11. j +=2;  12.    13. case 0:  14. j +=4;  15. }  16.      What is the value of j at line 16?()

    • A、 0
    • B、 1
    • C、 2
    • D、 4
    • E、 6

    正确答案:A,E

  • 第23题:

    单选题
    public class SwitchTest {   public static void main (String args) {   System.out.PrintIn(“value =” +switchIt(4));   }   public static int switchIt(int x) {   int j = 1;   switch (x) {   case 1: j++;   case 2: j++;   case 3: j++;  case 4: j++;   case 5: j++;   default:j++;   }   return j + x;   }   }   What is the output from line 3? ()
    A

     Value = 3

    B

     Value = 4

    C

     Value = 5

    D

     Value = 6

    E

     Value = 7

    F

     Value = 8


    正确答案: C
    解析: 暂无解析