给定如下Java代码片段,编译运行时的结果是() int i=2; switch(i) { default: System.out.println(“default”); case 0: System.out.println(“zero”); break; case 1: System.out.println(“one”); case 2: System.out.println(“two”); }A.输出:defaultB.输出:default zeroC.编译出错,default 语句位置不符合swit

题目

给定如下Java代码片段,编译运行时的结果是() int i=2; switch(i) { default: System.out.println(“default”); case 0: System.out.println(“zero”); break; case 1: System.out.println(“one”); case 2: System.out.println(“two”); }

A.输出:default

B.输出:default zero

C.编译出错,default 语句位置不符合switch结构的语法结构

D.输出two


相似考题
更多“给定如下Java代码片段,编译运行时的结果是() int i=2; switch(i) { default: System.out.println(“default”); case 0: System.out.println(“zero”); break; case 1: System.out.println(“one”); case 2: System.out.println(“two”); }”相关问题
  • 第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题:

    public static void main(String[]args){Integer i=new Integer(1)+new Integer(2);switch(i){case3:System.out.println("three");break;default:System.out.println("other");break;}}Whatistheresult?()

    A.three

    B.other

    C.Anexceptionisthrownatruntime.

    D.Compilationfailsbecauseofanerroronline12.

    E.Compilationfailsbecauseofanerroronline13.

    F.Compilationfailsbecauseofanerroronline15.


    参考答案:A

  • 第3题:

    编译和执行以下代码,输出结果是( )。 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


    正确答案:C

  • 第4题:

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

  • 第5题:

    给出下列的程序片段,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


    正确答案:D

  • 第6题:

    以下程序段的输出结果为( )。 int j=2 switch (j){ Case 2: system.out.print("two."): Case 2+1: System.out.println("three."); break: default: System.out.println (“value is”+j): Break }A.B.two

    A.two.three.

    B.two

    C.three

    D.value is 2


    正确答案:A

  • 第7题:

    给出下面代码段: 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: break; default: System.out.println("default"); } } } 下列m的值能引起输出“default”的是( )。

    A.0

    B.1

    C.2

    D.4


    正确答案:D
    解析:本题考查条件语句switch的应用。此代码段最后输出default,则表示m的值不能为0、1和2三者其中之一,故m的值只能选择D。

  • 第8题:

    有如下代码段:

    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


    正确答案:BC

  • 第9题:

    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

  • 第10题:

    public static void main(String[]args){ Integer i=new Integer(1)+new Integer(2); switch(i){ case3:System.out.println("three");break; default:System.out.println("other");break; } } Whatistheresult?()

    • A、three
    • B、other
    • C、Anexceptionisthrownatruntime.
    • D、Compilationfailsbecauseofanerroronline12.
    • E、Compilationfailsbecauseofanerroronline13.
    • F、Compilationfailsbecauseofanerroronline15.

    正确答案:A

  • 第11题:

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


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

  • 第12题:

    单选题
    public static void main(String[]args){ Integer i=new Integer(1)+new Integer(2); switch(i){ case3:System.out.println("three");break; default:System.out.println("other");break; } } Whatistheresult?()
    A

    three

    B

    other

    C

    Anexceptionisthrownatruntime.

    D

    Compilationfailsbecauseofanerroronline12.

    E

    Compilationfailsbecauseofanerroronline13.

    F

    Compilationfailsbecauseofanerroronline15.


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

  • 第13题:

    classTestApp{publicstaticvoidmain(String[]args){intx=5;switch(x){case1:case2:case3:System.out.println(一季度”);break;case4:case5:case6:System.out.println(二季度”);case7:case8:case9:System.out.println(三季度”);break;ase10:case11:ase12:System.out.println(四季度”);break;default:System.out.println(不是有效的月份”);}}}上述程序运行后的结果是哪项?()

    A.一季度

    B.二季度

    C.三季度

    D.四季度


    参考答案:B

  • 第14题:

    下面程序的输出结果是( )。 public class Sun { public static void main(String args[ ]) { int i = 1; switch (i) { case 0: System.but.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


    正确答案:C
    解析:该题考查对switch-case-break的理解。每个分支语句后面必须有break语句,否则程序向下执行,直到遇到break语句或程序结束。所以,该题i=1时执行casel分支语句,而casel分支语句后没有break语句,程序继续向下执行case2分支语句和 default分支语句。A只执行了case 1:B只执行了casel和default;C:只执行了default。故本题的正确答案是C。

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

    给出下列的程序段,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


    正确答案:D

  • 第17题:

    给出下列的程序代码片段,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


    正确答案:D
    解析:此题考查switch语句的用法,switch的判断的条件必须是一个int型值,也可以是byte,short和char型的值,case中需要注意的是一个case后面一般要接一个break语句才能结束判断,否则将继续执行其他case而不进行任何判断,如果没有任何值符合CaSe列出的判断,则执行default的语句,default是可选的,可以没有,如果没有default而又没有任何值匹配case中列出的值,则switch不执行任何语句。

  • 第18题:

    下面程序段的输出结果是( )。 public class Test{ public static void main(String args[]){ int i=1: switch(i){ case0: System.OUt.println("0"); break; casel: System.out.println("1"); case2: System.OUt.println("2"); break; default: System.out.println("default"); } } }

    A.01

    B.12

    C.10

    D.21


    正确答案:B
    B。【解析】本题考查switch-case-break的用法。每个分支语句后面必须有break语句,否则程序向下执行,直到遇到break语句或程序结束。所以该题i=1时执行easel分支语句,而casel分支语句后没有break语句,程序继续向下执行case2分支语句,case2语句后有break语句,故程序不执行default分支语句。

  • 第19题:

    以下程序的运行结果为?

    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

  • 第20题:

    研究下面的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时,运行结果是()。 

    • A、没有输出任何结果
    • B、输出结果为3
    • C、输出结果是3和4
    • D、输出结果是1、3和4

    正确答案:C

  • 第21题:

    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

  • 第22题:

    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(“不是有效的月份”);  }  }  }   上述程序运行后的结果是哪项?()  

    • A、一季度
    • B、二季度
    • C、三季度
    • D、四季度

    正确答案:B

  • 第23题:

    单选题
    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(“不是有效的月份”);  }  }  }   上述程序运行后的结果是哪项?()
    A

    一季度

    B

    二季度

    C

    三季度

    D

    四季度


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

  • 第24题:

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