java,string类练习题
java,string类练习题
一、选择题
1. 下列String类的方法返回指定字符串的一部分
A. extractstring B. substring C. Substring D. Middlestring
2.下列哪一个是正确的
A) HashTable的关键字和值都允许为null
B) HashTable的关键字和值都不允许为null
C) HashTable的关键字允许为null,值不允许为null D) HashTable的关键字不允许为null,值允许为null.对于下列代码:
String str1=“java”; String str2=“java”;
String str3=new String;
StringBuffer str4=new StringBuffer; 以下表达式的值为true的是 A) str1= =str2; C) str2= =str3;
B) str1= =str4; D) str3= =str4;
4.以下程序段输出结果的是
public class Test {
public static void main{String str=“ABCDE”;str.substring;str.concat;
System.out.print; }
}
A) DE B) DEXYZ C) ABCDED) CDEXYZ.对于下列代码:
public class Example{
String str=new String; char ch[]={‘d’,’b’,’c’};
public static void main{ }
public void change{ str=“world”;ch[0]= ‘a’;
}
Example ex=new Example; ex.change;
System.out.println;
}
B) hello and a
输出结果是: A) hello and d
C) world and d D) world and a.以下代码的运行结果是哪一项。
public class StringTest { } A)A.A C)A.B
B)B.A D)B.B
public static void mb_operate {}
public static void main { }
String a=“A”; String b=“B”; mb_operate;
System.out.println; x.concat; y=x;
7.以下代码的运行结果是哪一项。
public class StringArray Test {}
public static void mb_swap {}
public static void main { }
B)21 D)23
String [] s={“1”,”2”}; mb_swap;
System.out.print; if return; String t=s[0]; s[0]=s[1]; s[1]=t;
A)20 C)22
8.以下代码的运行结果是哪一项。
publicclassTestGetChars{
publicstaticvoidmain{
String myString = new String; char [] yourString = new char[16];
myString.getChars;
System.out.println;
System.out.println;
} }
A)Hello World! B)Hello World!
Hello Hello! C)Hello World! D)World
World
World
9.以下代码的运行结果是哪一项。
publicclassTestStringContructor{
publicstaticvoidmain{byte [] b = {49,50,51,52,53};} A)45555
B)12345
C