多选题下面哪段语法执行正确()AString s = Gone with the wind;String t =  good ;String k = s + t;BString s = Gone with the wind;String t; t = s[3] + one;CString s = Gone with the wind;String standard = s.toUpperCase();DString s = home directory;String t = s - directory;

题目
多选题
下面哪段语法执行正确()
A

String s = Gone with the wind;String t =  good ;String k = s + t;

B

String s = Gone with the wind;String t; t = s[3] + one;

C

String s = Gone with the wind;String standard = s.toUpperCase();

D

String s = home directory;String t = s - directory;

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

第1题:

假设有以下代码: String s="hello"; String t="hello"; char c[ ]={'h','e','l','l','o'}; 下列选项中,返回false的语句是______。

A.s.equals(t);

B.t.equals(c);

C.s==t;

D.t.equals(new String("hello"));


正确答案:B
解析: ==操作符所比较的是操作符两端的操作数是否是同一个对象,而String的equals( )方法所比较的是两个String对象的内容是否一样,其参数是一个String对象时才有可能返回true,其他对象都返回false。因此只有选项B符合题意。

第2题:

下面的程序执行后,屏幕上显示的应是 public class Exam{ public static void main(String[]args){ char char1[]={'t','e','s','t'}; char char2[]={'t','e','S','t','1'}; String s1=new String(char1); String s2=new String(char2,0,4); System.out.println(s1.equals(s2)); } }

A.true

B.false

C.test

D.编译错误


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

第3题:

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

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

第4题:

下列哪个程序段可能导致错误?

A.String s="hello"; String t= "good"; String k=s+ t;

B.String s="hello"; String t; t=s[3]+"one";

C.String s="hello"; String standard=s. toUpperCase

D.String s="hello"; String t =s+ "good"


正确答案:B
解析:选项A)String类型可以直接使用“+”运算符进行连接运算。选项B)String是一种Object,而不是简单的字符数组,不能使用下标运算符取其值的某个元素,错误。选项C)toUpperCase()方法是String对象的一个方法,作用是将字符串的内容全部转换为大写并返回转换后的结果(String类型)。选项D)同选项A)。

第5题:

String s=”Example String”; 下面哪些语句是正确的?()

A.s>>>=3;

B.int i=s.length();

C.s[3]=”x”;

D.String short_s=s.trim();

E.String t=”root”+s;


正确答案:BDE

第6题:

给出下面的代码,则以下( )选项返回true。 String s="hello"; String t="hello"; Char c[]={'h','e','l','l','o'};

A.s. equals (t) ;

B.t. equals (C);

C.s==t;

D.t==c;


正确答案:A
解析:==操作符比较的是操作符两端的操作数是否是同一个对象,而String的equals()方法比较的是两个String对象的内容是否一样,其参数是一个String对象时才有可能返回true,其他对象都返回假。

第7题:

已知如下定义: String s = "story"; 下面哪些表达式是合法的?()

A.s += "books";

B.char c = s[1];

C.int len = s.length;

D.String t = s.toLowerCase();


正确答案:AD

第8题:

下面的哪些程序段可能导致错误? ( ) Ⅰ: String s = "Gone with the wind"; String t = "good "; String k = s + t; Ⅱ: String s = "Gone with the wind"; String t; t = s[3] + "one"; Ⅲ: String s = "Gone with the wind"; String standard = s.toUpperCase(); Ⅳ: String s = "home directory"; String t = s-"directory":

A.Ⅱ、Ⅲ

B.Ⅱ、Ⅳ

C.Ⅰ、Ⅳ

D.Ⅲ、Ⅳ


正确答案:B
解析:本题是考杳对String操作符的理解和应用。Ⅰ段中,String类型可以直接使用+进行连接运算:Ⅱ段中,String是一种Object,而不是简单的字符数组,不能使用下标运算符取其值的某个元素,错误;Ⅲ段中, toUppelCase0方法是String对象的一个方法,作用是将字符串的内容全部转换为大写并返回转换后的结果(String类型);IV段中,String类型不能进行减(—)运算,错误。

第9题:

下列的哪个程序段可能导致错误? ( )

A.String s="hello"; String t="good"; String k=s+t;

B.String s="hello"; String t; t=s[3]+"one";

C.String s="hello"; String standard=s.toUpperCase();

D.String s="hello"; String t=s+"good";


正确答案:B

第10题:

给出下列的代码,则以下哪个选项返回true? String s="hello"; String t="hello"; char c []= {'h','e','1','1','o'};A)s.equals(t);

A.t. equals(

B.;

C.s==t;

D.t==c;


正确答案:A
解析:==操作符比较的是操作符两端的操作数是否是同一个对象,而String的equals()方法比较的是两个 String对象的内容是否一样。s. equals(t)方法比较字符串s与字符串t中的内容是否一致,两个字符串中的内容一致,所以返回true。

更多相关问题