单选题public static void main(String[]args){ String str="null"; if(str==null){ System.out.println("null"); }else(str.length()==0){ System.out.println("zero"); }else{ System.out.println("some"); } } What is the result?()A nullB zeroC someD Compilationfails.E

题目
单选题
public static void main(String[]args){ String str="null"; if(str==null){ System.out.println("null"); }else(str.length()==0){ System.out.println("zero"); }else{ System.out.println("some"); } } What is the result?()
A

null

B

zero

C

some

D

Compilationfails.

E

Anexceptionisthrownatruntime.

参考答案和解析
正确答案: D
解析: 暂无解析
如果没有搜索结果或未解决您的问题,请直接 联系老师 获取答案。
相似问题和答案

第1题:

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.


参考答案:D

第2题:

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

A.NULL

B.Compilationfails.

C.Thecoderunswithnooutput.

D.Anexceptionisthrownatruntime.


参考答案:B

NULLshouldbe"null".

第3题:

Give the following java class:public class Example{public static void main(String args[]){int x[] = new int[15];System.out.println(x[5]);}}Which statement is corrected?()

A.When compile, some error will occur.

B.When run, some error will occur.

C.Output is zero.

D.Output is null.


参考答案:C

第4题:

已知如下代码: public class Test long a[]=new long[10] public static void main (String args[]{ System.out.println(a[6];} 以下( )语句是正确的。

A.Output is null.

B.When running,some error will occur.

C.When compile,some error will occur.

D.Output is 0.


正确答案:D

第5题:

现有一个文件file21.txt,其内容是: abCdEf, 执行下列程序之后,输出的结果是______。 package ch1; import java,io.*; public class ex21 { static String name = "ch1\\file21.txt"; public static void main(String[] args) { try { readFile (); } catch(IOException ioe) { System.out.println(ioe.getMessage()); } } static void readFile () throws IOException { BufferedReader br = null; try { File f = new File(name); FileReader fr = new FileReader(f); br = new BufferedReader(fr); String str= br.readLine(); System.out.println(str.toLowerCase()); } finally if(br != null) br.close (); } } }

A.AbCdEf

B.abcdef

C.aBcDeF

D.ABCDEF


正确答案:B

第6题:

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)值。

第7题:

阅读下面程序 public class ConcatTest { public static void main(String[] args) { String str1="abc"; String str2="ABC": String str3=str1.concat(str2); System.out.println(str3); } } 程序运行的结果是

A.abc

B.ABC

C.abcABC

D.ABCabc


正确答案:C
解析:String类的concat方法原型为public String concat(String str),其功能是将指定字符串连到此字符串的末尾。如果参数字符串的长度为0,则返回此String对象。否则,创建一个新的String对象,用来表示由此String对象表示的字符序列和由参数字符串表示的字符序列串联而成的字符序列。所以本题中的结果为str1和str2串联而成的字符序列,即"abcABC"。

第8题:

public static void main(String[]args){String str="null";if(str==null){System.out.println("null");}else(str.length()==0){System.out.println("zero");}else{System.out.println("some");}}What is the result?()

A.null

B.zero

C.some

D.Compilationfails.

E.Anexceptionisthrownatruntime.


参考答案:D

第9题:

阅读下面程序 public class ConcatTest{ public static void main(String[] args) { String strl = "abc"; String str2 = "ABC"; String str3 = str1.concat(str2); System.out.println(str3); } } 程序的运行结果是:

A.abe

B.ABC

C.abcABC

D.ABCabc


正确答案:C
解析:本题考查字符串的使用。String类提供concat(str)方法,该方法将当前字符串对象与指定str字符串相连。题目程序中生成两个字符串变量str1和str2,并为其赋值,然后生成一个字符串变量str3,该字符串变量的值为表达式str1.concat(str2)的结果。表达式str1.concat(str3)是把字符串str1与字符串str2相连,结果为“abcABC”。
因此,程序的运行结果是“abcABC”。本题的正确答案是选项C。

第10题:

下面是一段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。

更多相关问题