计算机二级考试

解析:已知String str=new String ("Luck");,则

来源:网考网计算机二级 所有评论

【单选题】已知String str=new String ("Luck");,则下列关于str的操作中不合法的是( )。


A.String s=str. toUpperCase()
B.int i=Str. length;
C.char s=str. charAt(2);
D.String s="Good" +str;


网考网参考答案:B
网考网解析:

String类中有一个length()方法用于返回字符串的长度。但是在调用这个方法时应采用str. length()的形式,所以选项B不合法。选项A调用toUpperCase ()方法的功能是将字符串转换为大写;选项C调用的charAt ()方法的功能是获取字符串的指定字符,返回值为char类型;选项D中使用的运算符+可以实现字符串的连接操作。 document.getElementById("warp").style.display="none"; document.getElementById("content").style.display="block"; 查看试题解析出处>>

相关推荐

发布评论 查看全部评论