计算机二级

下列程序段的输出结果是( )。 String MyStr="Hello,"; Mystr=MyStr + "World!"; System.out.println(Mystr);A.Hello,World!B.Hello,C.World!D.该程序段有语法错误

题目

下列程序段的输出结果是( )。 String MyStr="Hello,"; Mystr=MyStr + "World!"; System.out.println(Mystr);

A.Hello,World!

B.Hello,

C.World!

D.该程序段有语法错误

参考答案和解析
正确答案:A
如果没有搜索结果,请直接 联系老师 获取答案。
相似问题和答案

第1题:

5、下面能够对字符串进行排序的方法有错误的是

A.def sort1(mystr):#mystr是字符串列表 mystr.sort()###SXB###B.def sort2(mystr):#mystr是字符串列表 n=len(mystr) for i in range(n): j=i m=j while j<n: if(mystr[j]<mystr[m]): m=j j+=1 mystr[i],mystr[m]=mystr[m],mystr[i]###SXB###C.def sort3(mystr):#mystr是字符串列表 #python的全局排序函数 mystr=sorted(mystr) return mystr###SXB###D.def sort4(mystr):#mystr是字符串列表 #冒泡排序 i=j=0 n=len(mystr) while(i<n-1): j=0 while j<n-i-1: if mystr[j]>mystr[j+1]: mystr[j],mystr[j+1] =
C

第2题:

对于下列程序,哪个叙述是正确的?() public class Test { public static void main(String[] args) { int m=100; if(m=100){ System.out.println("hello"); System.out.println("你好"); } else{ System.out.println("ok"); System.out.println("好的"); } } }

A.出现编译错误。

B.程序输出的结果是:ok好的

C.程序输出的结果是:ok

D.程序输出的结果是:hello你好


程序实现将磁盘文件infile.txt复制到磁盘文件outfile.txt

第3题:

下面能够对字符串进行排序的方法有错误的是

A.def sort1(mystr):#mystr是字符串列表 mystr.sort()#B.def sort2(mystr):#mystr是字符串列表 n=len(mystr) for i in range(n): j=i m=j while j<n: if(mystr[j]<mystr[m]): m=j j+=1 mystr[i],mystr[m]=mystr[m],mystr[i]#C.def sort3(mystr):#mystr是字符串列表 #python的全局排序函数 mystr=sorted(mystr) return mystr#D.def sort4(mystr):#mystr是字符串列表 #冒泡排序 i=j=0 n=len(mystr) while(i<n-1): j=0 while j<n-i-1: if mystr[j]>mystr[j+1]: mystr[j],mystr[j+1] =
D

第4题:

语句 System.out.println("Hello,world!"+4+8);的输出结果是Hello,world!48。()

此题为判断题(对,错)。


答案:对

第5题:

下列程序的输出结果是( )。 public class Test { public static void main (String[] args) { String s="hello"; s.replace ('r','m'); System.out.println(s); } }

A.hello

B.HELLO

C.hemmo

D.HEMMO


正确答案:A
解析:String类的replace (char oldChar,char newChar)函数的作用是返回一个新的字符串,它是通过用newChar替换此字符串中出现的所有oldChar而生成的。返回的是新字符串,但是原字符串变量的值并未发生改变。因此,输出的是“hello”而不是“hemmo”。如果替换语句换为: s=s.replace('l','m');,则输出“hemmo”。

第6题:

下列程序段的输出结果是 ( ) String MyStr="Hello,"; MyStr=MyStr+"World!"; System.out.println(MyStr);

A.Hello,World!

B.Hello.

C.World!

D.该程序段有语法错误


正确答案:A

第7题:

下列程序段的输出结果是 String MyStr = "Hello,"; MyStr = MyStr + "World!"; System.out.println(MyStr);

A.Hello,World!

B.Hello,

C.World!

D.该程序段有语法错误


正确答案:A
解析:String类型可以直接使用“+”进行连接运算。

第8题:

下列程序段的输出结果是( )。 String MyStr="Hello,"; MyStr=MyStr+"World!"; Sysmm.out.println(MyStr);

A.Hello,World!

B.Hello,

C.World!

D.该程序段有语法错误


正确答案:A

第9题:

下列程序段的输出结果是( )。 String MyStr="Hello,"; MyStr=MyStr+ "World!"; System.out.println(MyStr);

A.Hello, World!

B.Hello,

C.World!

D.该程序段有语法错误


正确答案:A
解析:本题主要考查String类型可以直接使用“+”进行连接运算。