niusouti.com

单选题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:

题目
单选题
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


相似考题
更多“单选题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:”相关问题
  • 第1题:

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

  • 第2题:

    1.publicclassSwitchTest{2.publicstaticvoidmain(String[]args){3.System.out.PrintIn(value=”+switchIt(4));4.}5.publicstaticintswitchIt(intx){6.intj=1;7.switch(x){8.case1:j++;9.case2:j++;10.case3:j++;11.case4:j++;12.case5:j++;13.default:j++;14.}15.returnj+x;16.}17.}Whatistheoutputfromline3?()

    A.Value=3

    B.Value=4

    C.Value=5

    D.Value=6

    E.Value=7

    F.Value=8


    参考答案:F

  • 第3题:

    publicclassSwitchTest{publicstaticvoidmain(Stringargs){System.out.PrintIn(value=”+switchIt(4));}publicstaticintswitchIt(intx){intj=1;switch(x){case1:j++;case2:j++;case3:j++;case4:j++;case5:j++;default:j++;}returnj+x;}}Whatistheoutputfromline3?()

    A.Value=3

    B.Value=4

    C.Value=5

    D.Value=6

    E.Value=7

    F.Value=8


    参考答案:F

  • 第4题:

    下面程序段的输出结果是( )。 public class Test t public static void main(String[] args) { int x=0; for (int i=1;i<=4;i++) { x=4; for(int j=1;j<=3; j++) { x=3; for(int k=1; k<=2; k++) x=x+6; } } System. out. println (x); } }

    A.36

    B.48

    C.144

    D.15


    正确答案:D
    解析:题目中是一个三个循环的嵌套,但是每次循环时,x都将重新赋值,所以只计算最后一次即可,x=3,执行了两次x=x+6,所以x=15,选D。

  • 第5题:

    下面程序段的输出结果是( )。 public class Test { public static void main (String[] args) { int j=2,i=5; while (j<i--) j++; System.out.println(j);} }

    A.2

    B.3

    C.4

    D.5


    正确答案:C
    解析:循环时,首先判断结束条件,25,然后i=4,j=3,继续循环,i=3,j=4,结果条件ji为假,退出循环,因此j=4。所以选C。

  • 第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题:

    下列程序执行之后,将输出 public class exl9 { public static void main(string[] args) { int x=3; int y=7; switch(y/x){ case 1: y*=2; break; case 2: y*=3; break; case 3: y*=4; break; default: y=0; } System.out.print(y); } }

    A.28

    B.21

    C.14

    D.0


    正确答案:B

  • 第8题:

    下列程序输出结果为( )。public class test { public static void main(String args[]) { int a=0; outer: for(int i=0;i<2;i++) { for(int j=0;j<2;j++) { if(j>i) { continue outer; } a++; } } System.out.println(a); }}

    A.0

    B.2

    C.3

    D.4


    正确答案:C

  • 第9题:

    1. public class SwitchTest {  2. public static void main (String []args)  {  3. System.out.PrintIn(“value =” +switchIt(4));  4. }  5. public static int switchIt(int x)  {  6. int j = 1;  7. switch (x) {  8. case 1: j++;  9. case 2: j++;  10. case 3: j++;  11. case 4: j++;  12. case 5: j++;  13. default:j++;  14. }  15. return j + x;  16. }  17. }     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

    正确答案:F

  • 第10题:

    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

  • 第11题:

    单选题
    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


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

  • 第12题:

    单选题
    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
    解析: 暂无解析

  • 第13题:

    以下程序的输出结果是()。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

  • 第14题:

    publicclassSwitchTest{publicstaticvoidmain(String[]args){System.out.println(value=+switchIt(4));}publicstaticintswitchIt(intx){intj=1;switch(x){case1:j++;case2:j++;case3:j++;case4:j++;case5:j++;default:j++;}returnj+x;}}Whatistheresult?()

    A.value=3

    B.value=4

    C.value=5

    D.value=6

    E.value=7

    F.value=8


    参考答案:F

  • 第15题:

    给出下面代码片段: 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


    正确答案:B

  • 第16题:

    给出下列代码段: 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.以上答案都不正确


    正确答案:C

  • 第17题:

    执行如下程序: 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


    正确答案:A
    解析:本题关键是要搞清楚该程序执行了哪几条语句。由于x的值等于1,所以switch结构中,程序从case1后面的语句开始执行,又因为case1后面的语句没有以break结束,所以程序要继续往下执行case 2后面的语句。所以,该程序共执行了这3条语句:a++;a++;b++;因此,变量a和b最后的值应该为2和1。

  • 第18题:

    下列语句序列执行后,j的值是______。 public class ex2 { public static void main(String[] args) { int j=2, i=5; while( j<i--) j++; System.out.println(j); } }

    A.3

    B.2

    C.4

    D.5


    正确答案:C

  • 第19题:

    以下程序运行后输出的结果是______。

    public class exl7

    {

    public static void main(String args [])

    {

    int a = 0;

    for(int j = 1; j <= 20; j++)

    if(j%5 != 0)

    a = a + j;

    System.out.println (a);


    正确答案:160
    160

  • 第20题:

    有如下程序 public class Sun { 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=0,b=0


    正确答案:A
    解析:该题考查对switch-case-break语句的理解。该题x=1与case1语句匹配,执行a++语句,a的值为1,而case1语句后没有break语句,所以程序继续向下执行case2语句,a++,b++,a的值为2,b的值为1。故本题答案选项是A。

  • 第21题:

    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

  • 第22题:

    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

    正确答案:F

  • 第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


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

  • 第24题:

    单选题
    1. public class SwitchTest {  2. public static void main (String []args)  {  3. System.out.PrintIn(“value =” +switchIt(4));  4. }  5. public static int switchIt(int x)  {  6. int j = 1;  7. switch (x) {  8. case 1: j++;  9. case 2: j++;  10. case 3: j++;  11. case 4: j++;  12. case 5: j++;  13. default:j++;  14. }  15. return j + x;  16. }  17. }     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


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