多选题Which of the following fragments might cause errors?()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 = 

题目
多选题
Which of the following fragments might cause errors?()
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;


相似考题
更多“多选题Which of the following fragments might cause errors?()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 = ”相关问题
  • 第1题:

    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

  • 第2题:

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

    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

  • 第3题:

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

    A.s.equals(t);

    B.t.equals(c);

    C.s = =t

    D.t = = c;


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

  • 第4题:

    下列的( )程序段可能导致错误。

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

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

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

    D.String s="hello": Stringt s +"good";


    正确答案:B

  • 第5题:

    下面的哪些程序片断可能导致错误() 

    • 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"

    正确答案:B,D

  • 第6题:

    Strings="This is the";Stringt=s.concat("String.");t的内容是()

    • A、This is the String
    • B、This is the
    • C、String

    正确答案:A

  • 第7题:

    现有:  import java.util.*;      class AddStuff2  {  public static void main(String  []  args)  {      TreeSett=new TreeSet();      if (t.add("one"))      if (t.add("two"))     if (t.add ("three"))  add("four");  for (String s  :  t)      System.out.print (s);     }      }      结果为:()     

    • A、 one
    • B、 one three two
    • C、 one two three
    • D、 one two three four
    • E、 four one three two
    • F、编译失败

    正确答案:E

  • 第8题:

    Which of the following fragments might cause errors?()    

    • 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";

    正确答案:B,D

  • 第9题:

    多选题
    下面的哪些程序片段可能导致错误()。
    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”;


    正确答案: D,C
    解析: 暂无解析

  • 第10题:

    单选题
    执行语句“stringstr("abc");”时,系统会自动调用string类的构造函数()。
    A

    string()

    B

    string(constchar*s)

    C

    string(conststring&str)

    D

    string(size_typen,charc)


    正确答案: B
    解析: 暂无解析

  • 第11题:

    单选题
    public String makinStrings() {  String s = “Fred”;  s = s + “47”;  s = s.substring(2, 5);  s = s.toUpperCase();  return s.toString();  }  How many String objects will be created when this method is invoked?()
    A

     1

    B

     2

    C

     3

    D

     4

    E

     5

    F

     6


    正确答案: A
    解析: 暂无解析

  • 第12题:

    单选题
    下面哪个是对字符串String的正确定义()。
    A

    String s1=null;

    B

    String s2=’null’;

    C

    String s3=(String)‘abc’;

    D

    String s4=(String)‘/uface’;


    正确答案: C
    解析: 暂无解析

  • 第13题:

    有以下等程序include void f(char *s, char *t){ chark; k=*s; *s=*t; *t=k; s++;t-

    有以下等程序#include <string. h>void f(char *s, char *t){ char k; k=*s; *s=*t; *t=k; s++; t--; if(*s) f(s, t);}main (){ char stt[10] ="abcdefg", *p; p=str+strlen (str)/2+1; f (p,p-2); print f ( "%s\n", str);}

    A.abcdefg

    B.gfedcba

    C.gbcdefa

    D.abedcfg


    正确答案:B
    解析:本题考查的是递归函数。在一个函数中直接或间接地调用了自身,则称此函数为递归函数。本题定义的函数f()就是一个递归函数。它先交换两个字符指针所指的内容,然后将第1个指针往后移动一位,第2个指针往前移动一位,如果第1个指针所指内容不是字符串结束标志,则递归调用自身。主函数中首先定义了一个字符数组sTR[10]="abcdefg",然后定义了一个字符指针p=str+strlen(str)/2+1,即让p指向str+4(或&str[4])的位置.然后调用f(p,p-2);,这使得p所指的str[4]及其以后的2个位置str[5]、str[6]中的内容同p-2所指的3tr[2]及其以前的2个位置str[1]、str[0]中的内容互相交换。即让整个字符串逆序。所以本题应该选择B。

  • 第14题:

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

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

  • 第15题:

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

    A.真

    B.假

    C.test

    D.编译错误


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

  • 第16题:

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

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

  • 第17题:

    public String makinStrings() {  String s = “Fred”;  s = s + “47”;  s = s.substring(2, 5);  s = s.toUpperCase();  return s.toString();  }  How many String objects will be created when this method is invoked?() 

    • A、 1
    • B、 2
    • C、 3
    • D、 4
    • E、 5
    • F、 6

    正确答案:C

  • 第18题:

    有语句String s=”hello world”; ,以下操作哪个是不合法的()

    • A、int i=s.length();
    • B、s>>>=3;
    • C、String ts=s.trim();
    • D、String t=s+”!”

    正确答案:B

  • 第19题:

    String s= "hello";     String t = "hello";  char c[] = {’h’,’e’,’l’,’l’,’o’} ;     Which return true?()   

    • A、 s.equals(t);
    • B、 t.equals(c);
    • C、 s==t;
    • D、 t.equals(new String("hello"));
    • E、 t==c;

    正确答案:A,C,D

  • 第20题:

    单选题
    有语句String s=”hello world”; ,以下操作哪个是不合法的()
    A

    int i=s.length();

    B

    s>>>=3;

    C

    String ts=s.trim();

    D

    String t=s+”!”


    正确答案: B
    解析: 暂无解析

  • 第21题:

    多选题
    下面哪段语法执行正确()
    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;


    正确答案: A,C
    解析: 暂无解析

  • 第22题:

    单选题
    Given: 11.String test = "Test A. Test B. Test C."; 12.// insert code here 13.String[] result = test.split(regex); Which regular expression, inserted at line 12,correctly splits test into "Test A","Test B",and "Test C"?()
    A

    String regex = ;

    B

    String regex =  ;

    C

    String regex = .*;

    D

    String regex = //s;

    E

    String regex = //.//s*;


    正确答案: E
    解析: 暂无解析

  • 第23题:

    多选题
    String s= "hello";     String t = "hello";  char c[] = {’h’,’e’,’l’,’l’,’o’} ;     Which return true?()
    A

    s.equals(t);

    B

    t.equals(c);

    C

    s==t;

    D

    t.equals(new String(hello));

    E

    t==c;


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