niusouti.com

publicstaticvoidmain(String[]args){Stringstr=null?;if(str==null){System.out.println(”null”);}else(str.length()==0){System.out.println(”zero”);}else{System.out.println(”some”);}}Whatistheresult?()A.nullB.zeroC.someD.Compilationfails.E.Anexceptionisthrownat

题目
publicstaticvoidmain(String[]args){Stringstr=null?;if(str==null){System.out.println(”null”);}else(str.length()==0){System.out.println(”zero”);}else{System.out.println(”some”);}}Whatistheresult?()

A.null

B.zero

C.some

D.Compilationfails.

E.Anexceptionisthrownatruntime.


相似考题
更多“publicstaticvoidmain(String[]args){Stringstr=null?;if(str==null){System.out.println(”null”);}else(str.length()==0){System.out.println(”zero”);}else{System.out.println(”some”);}}Whatistheresult?() ”相关问题
  • 第1题:

    publicstaticvoidparse(Stringstr){try{floatf=Float.parseFloat(str);}catch(NumberFormatExceptionnfe){f=0;}finally{System.out.println(f);}}publicstaticvoidmain(String[]args){parse(”invalid”);}Whatistheresult?()

    A.0.0

    B.Compilationfails.

    C.AParseExceptionisthrownbytheparsemethodatruntime.

    D.ANumberFormatExceptionisthrownbytheparsemethodatruntime.


    参考答案:B

  • 第2题:

    publicclassTest{publicstaticvoidmain(String[]args){Stringstr=NULL;System.out.println(str);}}Whatistheresult?()

    A.NULL

    B.Compilationfails.

    C.Thecoderunswithnooutput.

    D.Anexceptionisthrownatruntime.


    参考答案:B

    NULLshouldbe"null".

  • 第3题:

    下面是一段javabean程序,该程序的运行结果是 ( ) 。public class NullTest { public static void main(String[] ?args) { int M = 0; String str = null; StringBuffer sb = new StringBuffer("= "); sb.append(str); sb.append(M++); System.out.println(sb.toString()); } }

    A.=null
    B.=null0
    C.=null1
    D.=nullM

    答案:B
    解析:
    本题考查学生对javabean程序的熟悉程度,尤其是数值类型数据和字符串类型数据的掌握情况。M是整型变量,其值为0,str是字符串,sb是字符串空间,其中存放字符“=”,append是字符串添加函数,M++为自增运算符,它的特点是先取M的值作为表达式的值,再进行自增运算。程序的运算过程是:先将null拼接到“=”的后面,得字符串“=null”,再将0作为字符拼接到“=null”的后面,得“=null0”,M自增为1,输出结果为:=null0。

  • 第4题:

    Giventhefollowingcodefragment:1)Stringstr=null;2)if((str!=null)&&(str.length()>10)){3)System.out.println("morethan10");4)}5)elseif((str!=null)&(str.length()<5)){6)System.out.println("lessthan5");7)}8)else{System.out.println("end");}Whichlinewillcauseerror?()

    A.line1

    B.line2

    C.line5

    D.line8


    参考答案:C

    此题需要将代码仔细看清楚,查询没有逻辑错误,if…else的使用没有问题,也没有拼写错误,错误在于第5行的“与”操作符的使用,逻辑操作符(logicaloperator)的“与”应该是&&,而&是位逻辑操作符(bitwiselogicaloperator)的“与”,使用的对象不一样,逻辑操作符的“与”的左右操作数都应该是布尔型(logicalboolan)的值,而位逻辑操作符的左右操作数都是整型(integral)值。

  • 第5题:

    下面是一段javabean程序,该程序的运行结果是( )。public class NullTest{public static void main(String[]?args){int M=0;String str=null;StringBuffer sb=new StringBuffer("=");sb.append(str);sb.append(M++);System.out.println(sb.toString( ));}}

    A.=null
    B.=null0
    C.=null1
    D.=nullM

    答案:B
    解析:
    本题考查学生对javabean程序的熟悉程度,尤其是数值类型数据和字符串类型数据的掌握情况。M是整型变量,其值为0,str是字符串,sb是字符串空间,其中存放字符“=”,append是字符串添加函数,M++为自增运算符,它的特点是先取M的值作为表达式的值,再进行自增运算。程序的运算过程是:先将null拼接到“=”的后面,得字符串“=null”,再将0作为字符拼接到“=null”的后面,得“=null0”,M自增为1,输出结果为:=null0。