单选题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 threeB otherC Anexceptionisthrownatruntime.D Compilat

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


相似考题
参考答案和解析
正确答案: D
解析: 暂无解析
更多“单选题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 threeB otherC Anexceptionisthrownatruntime.D Compilat”相关问题
  • 第1题:

    ( 28 )请阅读下面程序

    public class ThreadTest {

    public static void main ( String args[ ]) throws Exception {

    int i=0;

    Hello t = new Hello ();

    ___________;

    whlle ( true ){

    System.out.println ( "Good Morning"+i++ ) ;

    if ( i=2 && t.isAlive ()){

    System.out.println ( "Main waiting for Hello ! ” );

    tjoin () ; // 等待 t 运行结束

    if ( i==5 ) break :}

    }

    class Hello extends Thread {

    int i ;

    public void run ()笼

    while ( true ){

    System.out.println ( "Hello"+i++ ) ;

    if ( i=5 ) break ;}}}

    为使该程序正确执行,下划线处的语句应是

    A ) t.sleep ()

    B ) t.yieldn ()

    C ) t.interrupt ()

    D ) t.start ()


    正确答案:D

  • 第2题:

    请阅读下面程序 public class ThreadTest{ public static void main(String args[])throws Ex- ception{ int i=0; Hello t=new Hello; ; while(true){ System.Out.println("Good Morning"+i++): if(i= =2t.isAlive){ System.out.println("Main waiting for Hel- lo!"); join;//等待t运行结束 } if(i= =5)break;} } } class Hello extends Thread{ int l; public void run{ while(true)( System.Out.println("Hell0"+i++); if(i= =5)break;)))

    A.t.sleep

    B.t.yield

    C.t.interrupt

    D.t.start


    正确答案:D
    D。【解析】程序中通过继承Thread类来创建线程,而Java中新创建的线程不会自动运行,必须调用线程的start方法,才能运行该线程。

  • 第3题:

    11.publicstaticvoidmain(String[]args){12.Integeri=uewInteger(1)+newInteger(2);13.switch(i){14.case3:System.out.println(”three”);break;15.default:System.out.println(”other”);break;16.}17.}Whatistheresult?()

    A.three

    B.other

    C.Anexceptionisthrownatruntime.

    D.Compilationfailsbecauseofanerroronline12.

    E.Compilationfailsbecauseofanerroronline13.

    F.Compilationfailsbecauseofanerroronline15.


    参考答案:A

  • 第4题:

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

  • 第5题:

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

  • 第6题:

     class Super {  public Integer getLenght() { return new Integer(4); } }  public class Sub extends Super {  public Long GetLenght() { return new Long(5); }  public static void main(String[] args) { Super sooper = new Super();  Sub sub = new Sub();  System.out.println(  sooper.getLenght().toString() + “,” +  sub.getLenght().toString() ); } }  What is the output?()  

    • A、 4,4
    • B、 4,5
    • C、 5,4
    • D、 5,5
    • E、 Compilation fails.

    正确答案:A

  • 第7题:

    class Beta {  public static void main(String [] args) {  Integer x = new Integer(6) * 7;  if (x != 42) {  System.out.print("42 ");  } else if (x 〈 new Integer(44-1)) {  System.out.println("less");  } else {  System.out.print("done"); } } }  结果是什么?() 

    • A、less
    • B、42
    • C、done
    • D、编译失败

    正确答案:A

  • 第8题:

    public static void main( String[] args ) {  Integer a = new Integer(10);  Integer b = new Integer(10);  Integer c = a;  int d = 10;  double e = 10.0;  }   Which three evaluate to true?()   

    • A、 (a == c)
    • B、 (d == e)
    • C、 (b == d)
    • D、 (a == b)
    • E、 (b == c)
    • F、 (d == 10.0)

    正确答案:A,B,F

  • 第9题:

    public class test {   public static void add3 (Integer i){  int val = i.intValue ( );   val += 3;   i = new Integer (val);    }     public static void main (String args [ ] )  { Integer i = new Integer (0);    add3 (i);   system.out.printIn (i.intValue ( ) );   }    }   What is the result?()

    • A、 Compilation will fail.
    • B、 The program prints “0”.
    • C、 The program prints “3”.
    • D、 Compilation will succeed but an exception will be thrown at line 3.

    正确答案:B

  • 第10题:

    单选题
    11. public static void main(String[] args) {  12. Integer i = uew Integer(1) + new Integer(2);  13. switch(i) {  14. case 3: System.out.println(”three”); break;  15. default: System.out.println(”other”); break;  16. }  17. }  What is the result?()
    A

     three

    B

     other

    C

     An exception is thrown at runtime.

    D

     Compilation fails because of an error on line 12.

    E

     Compilation fails because of an error on line 13.

    F

     Compilation fails because of an error on line 15.


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

  • 第11题:

    单选题
    public class Test {  public static void add3 (Integer i) {  int val = i.intValue();  val += 3;  i = new Integer(val); }  public static void main(String args[]) {  Integer i = new Integer(0);  add3(i);  System.out.println(i.intValue());  }  }   What is the result? ()
    A

     0

    B

     3

    C

     Compilation fails.

    D

     An exception is thrown at runtime.


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

  • 第12题:

    单选题
    class Beta {  public static void main(String [] args) {  Integer x = new Integer(6) * 7;  if (x != 42) {  System.out.print("42 ");  } else if (x 〈 new Integer(44-1)) {  System.out.println("less");  } else {  System.out.print("done"); } } }  结果是什么?()
    A

    less

    B

    42

    C

    done

    D

    编译失败


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

  • 第13题:

    下列程序中,实现将封装数据类型Integer和基本数据类型int之间的转换,以及Integer,int类型和String类型之间的转换。请将程序补充完整。

    程序运行结果如下:

    123

    456

    456

    public class ex7_1{

    public static void main(String[]args) {

    Integer intObj;

    int n;

    String s;

    intObj = new Integer(123);

    n=intObj.__________;

    System.out.printin(Integer.toString(n));

    s=new String("456");

    intObj=Integer._________;

    System.out.println(intObj.__________);

    n=Integer.parseInt(s);

    System.out.println(Integer.toString(n));

    }

    }


    正确答案:intValue() valueOf(s) toString()
    intValue() valueOf(s) toString() 解析:本题主要考查Java类库中对简单数据类型的封装以及对封装类型与基本类型之间的转换。解题关键是熟悉基本数据类型的封装,以及一些常用封装类型的常用转换方法,如Integer类的parseInt()方法等。本题中,第1个空,使用intValue()方法将封装对象intObj转换为基本的数据类型int;第2个空,使用valueOf()方法,将字符串转换为封装对象intObj;第3个空,使用toString()方法,将封装对象intObj转换为字符串打印出来,注意,这里不可以加参数。

  • 第14题:

    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

  • 第15题:

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

  • 第16题:

    下面程序段的输出结果是( )。 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分支语句。

  • 第17题:

    设有如下程序

    public class test {

    public static void main(String args[]) {

    Integer intObj=Integer.valueOf(args[args.length-1]);

    int i = intObj.intValue();

    if(args.length >1、

    System.out.println(i);

    if(args.length >0)

    System.out.println(i -1、;

    else

    System.out.println(i - 2、;

    }

    }

    运行程序,输入如下命令:

    java test 2

    则输出为:

    A. test

    B. test -1

    C. 0

    D. 1

    E. 2


    正确答案:D

  • 第18题:

    public class Test {  public static void add3 (Integer i) {  int val = i.intValue();  val += 3;  i = new Integer(val); }  public static void main(String args[]) {  Integer i = new Integer(0);  add3(i);  System.out.println(i.intValue());  }  }   What is the result? () 

    • A、 0
    • B、 3
    • C、 Compilation fails.
    • D、 An exception is thrown at runtime.

    正确答案:A

  • 第19题:

    11. public static void main(String[] args) {  12. Integer i = uew Integer(1) + new Integer(2);  13. switch(i) {  14. case 3: System.out.println(”three”); break;  15. default: System.out.println(”other”); break;  16. }  17. }  What is the result?() 

    • A、 three
    • B、 other
    • C、 An exception is thrown at runtime.
    • D、 Compilation fails because of an error on line 12.
    • E、 Compilation fails because of an error on line 13.
    • F、 Compilation fails because of an error on line 15.

    正确答案:A

  • 第20题:

    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

  • 第21题:

    多选题
    public static void main( String[] args ) {  Integer a = new Integer(10);  Integer b = new Integer(10);  Integer c = a;  int d = 10;  double e = 10.0;  }   Which three evaluate to true?()
    A

    (a == c)

    B

    (d == e)

    C

    (b == d)

    D

    (a == b)

    E

    (b == c)

    F

    (d == 10.0)


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

  • 第22题:

    单选题
    class Super {  public Integer getLenght() { return new Integer(4); } }  public class Sub extends Super {  public Long GetLenght() { return new Long(5); }  public static void main(String[] args) { Super sooper = new Super();  Sub sub = new Sub();  System.out.println(  sooper.getLenght().toString() + “,” +  sub.getLenght().toString() ); } }  What is the output?()
    A

     4,4

    B

     4,5

    C

     5,4

    D

     5,5

    E

     Compilation fails.


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

  • 第23题:

    单选题
    public class test {  public static void add3 (Integer i)  int val = i.intValue ( );  val += 3;  i = new Integer (val);  } public static void main (String args [ ] )  {  Integer  i = new Integer (0);  add3 (i);  system.out.printIn (i.intValue ( )  );  } What is the result?()
    A

     Compilation will fail.

    B

     The program prints “0”.

    C

     The program prints “3”.

    D

     Compilation will succeed but an exception will be thrown at line 3.


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