设有定义:String s=“World”;,下列语

题目

设有定义: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
如果没有搜索结果或未解决您的问题,请直接 联系老师 获取答案。
相似问题和答案

第1题:

下面是一个类的定义,试将程序补充完整。

class A{

String s;

____int a=66;

A(String sl){

s=sl;

}

static int geta(){

return a;

}

}


正确答案:static
static 解析:本题考查Java中的修饰符。static方法只能处理static成员,非static方法不能处理static成员。所以题目中的geta()方法声明是static的,所以其中的变量必须也声明为 static属性。

第2题:

阅读下列代码 public class Test{ String s="One World One Dream"; public static void main(String args[]){ System. out. println(s); } } 其运行结果是

A.args

B.One World One Dream

C.s

D.编译时出错


正确答案:D
解析:字符串s没有被声明成静态的,题中当主函数调用打印函数输出s的内容时,Test类还没有被实例化,也就没有字符串常量s了。可将字符串s声明为static类型的,或者在打印字符前先实例化Test类,再打印这个对象中的字符串。

第3题:

设有定义: char *c; ,以下选项中能够使字符型指针 c 正确指向一个字符串的是

A ) char str[ ]= "string";c=str;

B ) scanf("%s",c);

C ) c=getchar();

D ) *c="string";


正确答案:A

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

下列Applet程序中,指定s为字符串类型,将s绘制在屏幕上,请将程序补充完整。

import java.applet.Applet;

import java.awt.Craphics;

public class testl8_1 extends Applet {

______String s;

public void init ()

{

s=new String("Hello World");

}

public Void______(Graphics g) {

g.______(s,10,25);

}

}


正确答案:publicpaintdrawString
public,paint,drawString

第6题:

假设有以下代码: 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符合题意。

第7题:

设有如下的用户定义类型: Type Student number As String name As string age As Integer End Type 则以下正确引用该类型成员的代码是______。

A. Student name="李明”

B.Dim s As Student s.name="李明"

C.Dim s As Type Student s.name="李明"

D.Dim s As Type s.name="李明"


正确答案:B
解析:题目中所给出的是用户自定义类型,在这里注意新类型的名称是Student,所以选项CD均不正确;对于类型成员的引用是:对象,属性(方法),所以选项A不正确。

第8题:

设有定义:char*c;,以下选项中能够使字符型指针c正确指向一个字符串的是( )

A)char str[]="string";c=str;

B)scanf("%s",c);

C)c=getchar;

D)char str[]="string";strcpy("c,str")


正确答案:A

第9题:

阅读下面代码 public class Test { String s="One World One Dream"; public static void main(String[] args) { System.out.println(s); } } 其运行的结果是

A.args

B.World One Dream

C.s

D.编译时出错


正确答案:D

第10题:

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

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

更多相关问题