参考答案和解析
正确答案:BDE
更多“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;”相关问题
  • 第1题:

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

    A.s += "books";

    B.char c = s[1];

    C.int len = s.length;

    D.String t = s.toLowerCase();


    正确答案:AD

  • 第2题:

    Given: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*";

    F.String regex="\\w[\.]+";


    参考答案:E

  • 第3题:

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

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

  • 第4题:

    下列语句能给数组赋值,而不使用for循环的是

    A.myArray{[1]="One";[2]="Two";[3]="Three";}

    B.String s[5]=new String[] {"Zero","One","Two","Three","Four"};

    C.String s[]=new String[] {"Zero","One","Two","Three","Four"};

    D.String s[]=new String[]= {"Zero","One","Two","Three","Four"};


    正确答案:C
    解析:字符串数组赋初值的方法有两种,一种是如选项C一样初始化。另外一种是先为每个数组元素分配引用空间,再为每个数组元素分配空间并赋初值。例如还可做如下赋值:
      string s[]=new String[5];
      s[0]="Zero";
      s[1]="One";
      s[2]="Two";
      s[3]="Three";
      s[4]="Four";

  • 第5题:

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

    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

  • 第6题:

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

    • 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

  • 第7题:

    下面哪个语句是正确的()

    • A、short s=256;
    • B、String s=‘Helloworld’;
    • C、int x=012;
    • D、char c=“a”;

    正确答案:A,C

  • 第8题:

    设有定义:String s=“World”;,下列语句错误的是()。

    • A、int m=s.indexOf(‘r’);
    • B、char c=s.charAt(0);
    • C、int n=s.length();
    • D、String str=s.append(‘2’);

    正确答案:D

  • 第9题:

    已知Strings=“Java”,则下面哪些代码是正确的()

    • A、s=s+1;
    • B、char c=s[3];
    • C、int i=s.length;
    • D、String t=s+new Object();

    正确答案:A,D

  • 第10题:

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

    int i=s.length();

    B

    s>>>=3;

    C

    String ts=s.trim();

    D

    String t=s+”!”


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

  • 第11题:

    多选题
    下面哪段语法执行正确()
    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
    解析: 暂无解析

  • 第12题:

    多选题
    已知Strings=“Java”,则下面哪些代码是正确的()
    A

    s=s+1;

    B

    char c=s[3];

    C

    int i=s.length;

    D

    String t=s+new Object();


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

  • 第13题:

    顺序执行下列两条语句,输出结果是______。

    String s="You are a pretty boy!";System.out.println(s.length( ));


    正确答案:19
    19 解析: 提取字符串的长度可以用length( )方法,它将返回字符串的字符个数。

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

  • 第15题:

    下列语句能给数组赋值而不使用for循环的是

    A.myArray{[1]="One";[2]="Two";[3]="Three";}

    B.String s[5]=new String[]{"Zero", "One", "Two", "There", "Four"};

    C.String s[]=new String[]{"Zero", "One", "Two", "There", "Four"};

    D.String s[]=new String[]=|"Zero", "One", "Two", "There", "Four"};


    正确答案:C
    解析:A)、D)语法不正确,B)中s[5]的形式只能通过for循环的格式进行赋值,而不能直接赋值。C)中表达式左侧的“[]”说明现在定义一个数组,不需要指明数组长度,而表达式右侧“[]”在后面直接紧跟初始内容时也是不需要指定数组大小的,数组大小直接由初值长度决定。

  • 第16题:

    下面的表达式中正确的是 ( )

    A.String s=“你好”;int i=3;s+=i;

    B.String s=“你好”;int i=3;if(i==s){s+=i};

    C.String s=“你好”;int i=3;s=i+s;

    D.String s=“你好”;int i=3; s=i+;


    正确答案:A

  • 第17题:

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

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

  • 第18题:

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

    • 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

  • 第19题:

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

    • A、String s1=null;
    • B、String s2=’null’;
    • C、String s3=(String)‘abc’;
    • D、String s4=(String)‘/uface’;

    正确答案:A

  • 第20题:

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

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

    正确答案:B

  • 第21题:

    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

  • 第22题:

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

  • 第23题:

    单选题
    有语句Strings=”helloworld”;,以下操作哪个是不合法的?()
    A

    inti=s.length()

    B

    s>>>=3

    C

    Stringts=s.trim()

    D

    Stringt=s+”!”


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