下列的( )程序段可能导致错误。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";

题目

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

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


相似考题
更多“下列的()程序段可能导致错误。A.String s="hello": Sting t="good"; String k=s+t;B.Sting s="h ”相关问题
  • 第1题:

    下列语句中错误的是

    A.String s[]={"how","are"};

    B.byte b=255;

    C.String s="one"+"two";

    D.int i=2+2000;


    正确答案:B
    解析:类型不匹配,int类型不能默认转换为byte类型。

  • 第2题:

    已知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中使用的运算符+可以实现字符串的连接操作。

  • 第3题:

    以下程序是计算1 - 1/2 + 1/3 - 1/4 + … + 1/9 - 1/10 的值并输出,请补充完整。

    S=0

    K=1

    T=1

    DO WHINE K<【 】

    S=S+T/K

    K=K+1

    T= -T

    LOOP

    MSGBOX S


    正确答案:11
    11 解析:由于要计算的表达式的项数是10,因此答案为11。

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

  • 第5题:

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

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

  • 第6题:

    下面的哪些程序段可能导致错误? ( ) Ⅰ: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,而不是简单的字符数组,不能使用下标运算符取其值的某个元素,错误;Ⅲ段中, toUpperCase()方法是String对象的一个方法,作用是将字符串的内容全部转换为大写并返回转换后的结果(String类型);Ⅳ段中,String类型不能进行减(-)运算,错误。

  • 第7题:

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

  • 第8题:

    给出下面程序: public class ex51 { public static void main(String[] args) { String s = "hello"; String t = "hello"; char c[] = {'h', 'e', '1', '1', 'o'}; System. out. println (______) } } 在程序的横线处填入下列______选项后,程序输出的结果是true。

    A.t.equals(c)

    B.s.equals?

    C.s == t

    D.t == c


    正确答案:C

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

    正确答案:A,C

  • 第10题:

    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

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

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

  • 第13题:

    给出下面的代码,则以下( )选项返回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,其他对象都返回假。

  • 第14题:

    有以下程序:includevoid f(char *s, char *t){ char k;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 str[10]="abcdefg",*p; p=str+strlen(str)/2+ 1; f(p,p-2); printf("%s\n", str);}程序运行后的输出结果是( )。

    A.abcdcfg

    B.gfedcba

    C.gbcdefa

    D.abedcfg


    正确答案:B
    解析:本题定义的函数f()是一个递归函数。它先交换两个字符指针所指的内容,然后将第1个指针往后移动—位,第2个指针往前移动一位,如果第1个指针所指内容不是字符串结束标志,则递归调用自身。主函数中首先定义了—个字符数组sir[10]=“ahcdeft”然后定义了一个字符指针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所指的str[p]及其以前的2个位置str[1]、str[0]中的内容互相交换。即让整个字符串逆序。所以本题应该选择B。

  • 第15题:

    有以下程序:includevoid f(char*s,char*t){ char k;k=*s;*s=*t;*t=k;s++;t--;if(*s)f

    有以下程序: #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 str[10]="abcdefg",*p; p=str+strlen(str)/2+1; f(p,p-2); printf(~%s\n",str); } 程序运行后的输出结果是 ______。

    A.abcdef

    B.gfedcba

    C.gbcdefa

    D.abedcfg


    正确答案:B
    解析:p=str+strlen(str)/2+1=str+4,f(p,p-2)的功能是将p[4]与p[2]互换,p[5]与p[1]互换,p[6]与p[0]互换,最后的结果为gfedcba。

  • 第16题:

    有以下程序: include void f(char *s,char *t) {char k; k=*s; +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.str[10]="abcdefg",*p; p=str+strlen(str) /2+1; f(p,p-2); printf("%s\n",str); } 程序运行后的输出结果是 ______。

    A.abcdefg

    B.gfedcba

    C.gbcdefa

    D.abedcfg


    正确答案:B
    解析:本程序的作是将字符串str倒序。语句“p=str+strlen(str)/2+1;”用于将指针变量p指向e字符所在的存储单元,p-2指向了c字符所在的存储单元,在函数f中将这两个存储单元的内容交换,并使得f函数中指向c字符的指针变量s加1。指向c字符的指针变量t减1,然后继续将s和t指向的存储单元的内容进行交换,直到s指向的存储单元的内容为空为止。所以本题程序输出的结果是字符串“abcdefg”的倒序形式“gfedcba”。

  • 第17题:

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

  • 第18题:

    有以下程序: include include void f(char * s,char*t){char k; k=*s;*s=*

    有以下程序: #include <stdio.h>#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 str[10] :"abedefg", * p; p = str + strlen(str)/2+1; f(p,p -2); printf( "% s \n" ,str);程序运行后的输出结果是( )。

    A.abcdefg

    B.gfedcba

    C.gbcdefa

    D.abedcfg


    正确答案:B
    解析:本程序的作用是将字符串str倒序。语句p=str+strlen(str)/2+1;将指针变量p指向字符'e'所在的存储单元,P-2指向字符,'c'所在的存储单元,在函数f中将这两个存储单元的内容交换,然后将f函数中指向字符'e'的指针变量s加1,指向字符'c'的指针变量t减1,继续将s和t指向的存储单元的内容进行交换,直到s指向的存储单元的内容为空为止。所以本题程序输出的结果是字符串"abcdefe”的倒序形式"gfedcba"。

  • 第19题:

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

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

  • 第20题:

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

    • 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

  • 第21题:

    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

  • 第22题:

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


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

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


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