java常用类习题

上传人:第*** 文档编号:34226096 上传时间:2018-02-22 格式:DOC 页数:12 大小:109KB
返回 下载 相关 举报
java常用类习题_第1页
第1页 / 共12页
java常用类习题_第2页
第2页 / 共12页
java常用类习题_第3页
第3页 / 共12页
java常用类习题_第4页
第4页 / 共12页
java常用类习题_第5页
第5页 / 共12页
点击查看更多>>
资源描述

《java常用类习题》由会员分享,可在线阅读,更多相关《java常用类习题(12页珍藏版)》请在金锄头文库上搜索。

1、1Java 常用类习题一、选择题1. 下列 String 类的( B)方法返回指定字符串的一部分(选择一项)A. extractstring()B. substring()C. Substring()D. Middlestring()2下列哪一个是正确的( A )A) HashTable 的关键字和值都允许为 nullB) HashTable 的关键字和值都不允许为 nullC) HashTable 的关键字允许为 null,值不允许为 nullD) HashTable 的关键字不允许为 null,值允许为 null3对于下列代码:String str1=java;String str2=ja

2、va;String str3=new String(java);StringBuffer str4=new StringBuffer(java);以下表达式的值为 true 的是( C )A) str1= =str2; B) str1= =str4; C) str2= =str3; D) str3= =str4;4以下程序段输出结果的是( C )public class Test public static void main(String args)String str=ABCDE;str.substring(3);str.concat(XYZ);System.out.print(str);

3、A) DE B) DEXYZ C) ABCDE D) CDEXYZ5对于下列代码: public class ExampleString str=new String(hello);char ch=d,b,c;public static void main(String args)Example ex=new Example();ex.change(ex.str,ex.ch);System.out.println(ex.str+ and +ex.ch0);public void change(String str,char ch)str=world;ch0= a;2输出结果是: ( B )A)

4、 hello and d B) hello and aC) world and d D) world and a6以下代码的运行结果是哪一项。( C )public class StringTestpublic static void mb_operate(String x,String y)x.concat(y);y=x;public static void main (String args)String a=A;String b=B;mb_operate(a,b);System.out.println(a+.+b);A)A.A B)B.AC)A.B D)B.B7以下代码的运行结果是哪一项

5、。( B )public class StringArray Testpublic static void mb_swap(String s)if(s.length0)?s.length():0; S.length 空指针异常18给定下列程序:public class Testpublic static void main(String args)String str=new String(World);char ch=C,e,l,l,o;change(str,ch);System.out.println(str+and+ch);public static void change(String

6、 str,char ch)str=Changed;ch0=H;上述程序的运行结果应该是?( B )A) World and Cello B) World and HelloC) Changed and Hello D) Changed and Cello19在 java 语言中,下列表达式返回 true 的是哪些项目。( AB )A) hello=hello =内存地址都要一样 B) word.equals(word) C) john=john D) john.equals(new Button(john)20下面的哪些程序片断可能导致错误?( BD )A) String s=Hello; B

7、) String s=Hello;String t=World; String t;String k=s+t; t=s3+one;C) String s=Hello; D) String s=Hello World;String standard = s.toUpperCase(); String t=s-World;21在 java 语言中,下列语句中正确的是哪个?( D )A) String temp=new Stringa b c;B) String temp=a ,b ,c;C) String temp=a b c;D) String temp=a,b,c;22下面的哪些叙述为真? (

8、 ABCD )A) equals()方法判定引用值是否指向同一对象。B) = 操作符判定两个分立的对象的内容和类型是否一致。C) equals()方法只有在两个对象的内容一致时返回 true。 6D) 类 File 重写方法 equals()在两个分立的对象的内容和类型一致时返回 true。 23关于以下程序段,正确的说法是 ( A )1 String s1=Hello;2 String s2=Hello;3 if(s1= =s2)4 System.out.println(s1= =s2);5 if (s1.equals(s2)6 System.out.println(s1.equals(s2

9、) );A. 行 4 与行 6 都将执行 B. 行 4 执行,行 6 不执行C. 行 6 执行,行 4 不执行D. 行 4、行 6 都不执行24要产生20,999之间的随机整数使用哪个表达式? ( B )A(int)(20+Math.random()*97)B. 20+(int)(Math.random()*980)C. (int)Math.random()*999D. 20+(int)Math.random()*98025下列程序运行的结果为: ( B )public class Example String str=new String(good); char ch=a,b,c; publ

10、ic static void main(String args) Example ex=new Example(); ex.change(ex.str,ex.ch); System.out.print(ex.str+ and ); Sytem.out.print(ex.ch); public void change(String str,char ch) str=test ok; ch0=g; A. good and abc B. good and gbc C. test ok and abc D. test ok and gbc 26设有如下程序public class test publi

11、c static void main(String args) Integer intObj=Integer.valueOf(argsargs.length-1);int i = intObj.intValue();if(args.length 1) 7System.out.println(i);if(args.length 0)System.out.println(i - 1);else System.out.println(i - 2); 运行程序,输入如下命令:java test 2 则输出为: ( D )A. test B. test -1 C. 0 D. 1 E. 2 27下列程序运

12、行的结果为: ( E )public class test public static void main(String args) int i;float f = 2.3f;double d = 2.7;i = (int)Math.ceil(f) * (int)Math.round(d); System.out.println(i);A. 4 B. 5 C. 6 D. 6.1 E. 9 28.如果以下条件成立,则用到 java.lang.Math 类中哪个方法?method( -4.4 ) = -4; ( AF )A. round() B. min() C. trunc() D. abs()

13、E. floor() F. ceil()29.set 集合如何处理重复元素 ( )A如果加入一个重复元素将抛出异常B如果加入一个重复元素 add 方法将返回 falseC. 集合通过调用 equals 方法可以返回包含重复值的元素。D. 重复值将导致编译出错。30.以下哪个方法是 Vector 类中增加一个新元素的方法。 ( )AaddElement B. insert C. append D. addItem31. 以下哪些方法是 Collection 接口的方法? ( )A. iterator B. isEmpty C. toArray D. setText32.对于以下声明:String

14、 s1=hello;String s2=world;String s3;下面的操作合法的是( A )A)s3=s1+s2; B)s3=s1-s2; C)s3=s133.下面的程序段执行后输出的结果是( A )。8StringBuffer buf=new StringBuffer(Beijing2008);buf.insert(7,);System.out.println(buf.toString();A、 Beijing2008 B、 Beijing2008 C、 Beijing2008 D、 Beijing#2008 二、程序阅读题1、阅读下面的程序: public class Test public static void main(String a) int i = Integer.parseInt(a0); switch (i) case 1:System.out.println(Frist season);break; case 2:System.out.println(Second

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 办公文档 > 解决方案

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号