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

题目

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

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

  • 第3题:

    下列语句能给数组赋值而不使用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)中表达式左侧的“[]”说明现在定义一个数组,不需要指明数组长度,而表达式右侧“[]”在后面直接紧跟初始内容时也是不需要指定数组大小的,数组大小直接由初值长度决定。

  • 第4题:

    以下4组表达式中结果是逻辑值.T.的是_________。

    A.'this'$'this is a string'

    B.'this'$'THIS IS A STRING'

    C.'this is a string'S'this'

    D.'this'>'this is a string'


    正确答案:A
    解析:$函数是判断前一个字符串是否包含在后一个字符串中,在字符串中大小写字符串是区分开的。所以选项B、C不正确。当比较两个字符串时,系统对两个字符串的字符自左向右逐个进行比较,一但发现两个对应字符不同,就根据这两个字符的排列序列决定两个字符串的大小。

  • 第5题:

    给出下列的代码则以下哪个选项返回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。

  • 第6题:

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

    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

  • 第7题:

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

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

  • 第8题:

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

    • 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题:

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

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

    正确答案:A

  • 第10题:

    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

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


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

  • 第12题:

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

  • 第13题:

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

    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

  • 第14题:

    给出下列的代码,则以下哪个选项返回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。

  • 第15题:

    下列程序执行后,屏幕上显示的应是 public class Testyyy {public static void main(String[]args) {char charl[]={,'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.假

    C.test

    D.编译错误


    正确答案:A
    解析:①可以通过字符数组来生成一个字符申对象:String(char[]value);String(charC[]value,intstartIndex,intnumChars);其中,startIndex指定字符串在数组中的起始下标,numChars表示字符个数。②测试字符串是否相等,可用equals()方法,两串相等则返回true,否则返回false。

  • 第16题:

    下列语句能给数组赋值,而不使用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";

  • 第17题:

    下面的程序执行后,屏幕上显示的应是 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正确。

  • 第18题:

    给出下列的代码,则以下( )选项返回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

  • 第19题:

    下面程序执行后,屏幕上显示的应是______。 public class Testl0 { 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 (si.equal (s2)); } }

    A.true

    B.假

    C.test

    D.编译错误


    正确答案:A
    解析:首先可以通过字符数组来生成一个字符串对象:String(char[]value);String(char[]value,intstartlndex,intnumChars);其中,startlndex指定字符串在数组中的起始下标,numChars表示字符个数。然后再测试字符串是否相等,可调用equal()方法,两串相等则返回true,否则返回false。

  • 第20题:

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

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

    正确答案:A

  • 第21题:

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

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

    正确答案:B

  • 第22题:

    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

  • 第23题:

    多选题
    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;


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