Java程序设计

单选题Strings="This is the";Stringt=s.concat("String.");t的内容是()A This is the StringB This is theC String

题目
单选题
Strings="This is the";Stringt=s.concat("String.");t的内容是()
A

This is the String

B

This is the

C

String

如果没有搜索结果,请直接 联系老师 获取答案。
如果没有搜索结果,请直接 联系老师 获取答案。
相似问题和答案

第1题:

There are two character strings:s and t.s="My favor is computer",t=substr(s,9,5).Then the result after operation is

A.S="My favor is computer"; t="compu";

B.S="My favor is computer"; t="is co";

C.S="My favor"; t="is co";

D.S="My favor"; t="is computer";


正确答案:B

第2题:

现有:importjava.util.*;classAddStuff2{publicstaticvoidmain(String[]args){TreeSett=newTreeSet();if(t.add("one"))if(t.add("two"))if(t.add("three"))add("four");for(Strings:t)System.out.print(s);}}结果为:()

A.one

B.onethreetwo

C.onetwothree

D.onetwothreefour

E.fouronethreetwo

F.编译失败


参考答案:E

第3题:

He tried to show me how it ______ but he couldn ’t make it roll back up the string.

A. worked

B. functioned

C. rolled

D. did


参考答案:A

第4题:

下面的程序执行后,屏幕上显示的应是( )。 publicclassExam{ publicstaticvoidmain(String[]args){ charcharl[]={'t','e','s','t'}; charchar2[]={'t','e,'s','t','1'}; Strings1=newString(char1); Strings2=newString(char2,0,4); System.out.println(s1.equals(S2)); } }

A.true

B.false

C.test

D.编译错误


正确答案:A
解析: 本题考查考生对字符数组的理解。首先可以通过字符数组来生成一个字符串对象:String(char()value)和 String(char[]value,intstartlndex,intnumChars),其中,startlndex指定字符串在数组中的起始下标,numChars表示字符个数。然后再测试字符串是否相等,可调用equals()方法,两个字符串相等则返回true,否则返回false。题目中s1和s2都是“test”,所以最后返回是true,选项A正确。

第5题:

Strings="hello";Stringt="hello";charc[]={’h’,’e’,’l’,’l’,’o’};Whichreturntrue?()

A.s.equals(t);

B.t.equals(c);

C.s==t;

D.t.equals(newString("hello"));

E.t==c;


参考答案:A, C, D
这个在前面第10题的equals()方法和==操作符的讨论中论述过。==操作符比较的是操作符两端的操作数是否是同一个对象,而String的equals()方法比较的是两个String对象的内容是否一样,其参数是一个String对象时才有可能返回true,其它对象都返回假。需要指出的是由于s和t并非使用new创建的,他们指向内存池中的同一个字符串常量,因此其地址实际上是相同的(这个可以从反编译一个简单的测试程序的结果得到,限于篇幅不列出测试代码和反编译的分析),因此答案c也是正确的。

第6题:

下面程序段的输出结果是( ) classTest{ publicstaticvoidmain(Stringargs[]){ MyThreadt=newMyThread(); t.displayOutput("thasbeencreateD"); t.start(); } } ClassMyThreadextendsThread{ publicvoiddisplayOutput(Strings){ System.out.println(S); } publicvoidrun(){ displayOutput("tiSrunning."); } }

A.thasbeencreated.

B.thasbeencreated. TiSrunning.

C.tiSrunning.

D.编译出错


正确答案:A
解析: start()方法就可以启动该线程,线程也就处于可运行状态Runnable。Start()方法产生了线程运行需要的系统资源,并调用线程体,也就是Nn()方法,使得线程可以进入运行状态。程序运行时首先创建一个新的线程对象t,并调用 displayOutput(Srungs)方法输出thasbeencreatedo t.start()方法调用lain()方法,输出tisrunning,所以正确答案为选项A。

第7题:

importjava.util.*;publicclassLetterASort{publicstaticvoidmain(String[]args){ArrayListstrings=newArrayList();strings.add(?aAaA”);strings.add(”AaA”);strings.add(?aAa”);strings.add(”AAaa”);Collections.sort(strings);for(Strings:strings){System.out.print(s+);}}}Whatistheresult?()

A.Compilationfails.

B.aAaAaAaAAaaAaA

C.AAaaAaAaAaaAaA

D.AaAAAaaaAaAaAa

E.aAaAaAaAaAAAaa

F.Anexceptionisthrownatruntime.


参考答案:C

第8题:

下面哪段语法执行正确()

A.Strings="Gonewiththewind";Stringt="good";Stringk=s+t;

B.Strings="Gonewiththewind";Stringt;t=s[3]+"one";

C.Strings="Gonewiththewind";Stringstandard=s.toUpperCase();

D.Strings="homedirectory";Stringt=s-"directory";


参考答案:A, C

第9题:

A method returning length of the String.


正确答案:
 

第10题:

给定如下所示的JAVA代码,则运行时,会产生( )类型的异常Strings=null;s.concat("abc&quo

给定如下所示的JAVA代码,则运行时,会产生( )类型的异常

Strings=null;

s.concat("abc");

A.ArithmeticException

B.NullPointerException

C.IOException

D.ClassNotFoundException


正确答案:B

更多相关问题