ImageVerifierCode 换一换
格式:DOCX , 页数:26 ,大小:22.51KB ,
资源ID:9894296      下载积分:12 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/9894296.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(Java程序设计试题及答案.docx)为本站会员(b****8)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

Java程序设计试题及答案.docx

1、Java程序设计试题及答案JAVA程序设计试卷(A卷)得分阅卷人一、选择题(每小题 2分,共 40 分。)1JDK提供的编译器是( )。(A)java.exe (B)javac.exe(C)javap.exe (D)javaw.exe2.以下作为Java程序入口的main 方法声明正确的( )。(A)public void main(String args) (B)public int main(String args)(C)public static void main(String args) (D)public static int main(String args)3.以下标识符错误的

2、是( )。(A)Public (B)张三 (C)class (D)main4.java中定义字符串String s=”pzhu”,下面操作可以取得字符串长度的是( )。(A)s.length() (B)s.length (C)s.size() (D)length(s)5.如下定义数组,操作正确的是( )。int a=1,2,3;(A)a3=100 (B)a0.length (C)a+ (D)a.length6.如下定义二维数组操作错误的是( )。int a=1,2,3;(A)a01=200 (B)a0.length (C)a11=100 (D)a.length7. 以下数据类型存储空间最大的是

3、( )。(A)byte (B)long (C)float (D)char8. 面向对象的三大特性,不包括如下 ( )。(A)异常 (B)封装 (C)继承 (D)多态9、关于类的定义以下说法错误()。(A)类定义使用class关键字 (B)每个类中必须有一个main方法(C)一个包可以包含多个类 (D)java中所有类都是Object类的子类10. 关于构造方法以下说法错误的是 ( )。()构造方法名必须与类名一致 ()构造方法可以重载()构造方法是通过new来调用 ()每个类都必须编写构造方法代码11.关于继承如下说法错误的是( )。()Java是单继承的 ()通过extends来定义继承()

4、所有父类方法都可以被override的 ()继承呈现的是is a的关系12. 以下代码执行的结果是( )。System.out.println(攀枝花学院pzhu.length();()编译错误 ()运行错误 ()9 ()1413. 用来存储键值对的容器是( )。(A)ArrayList (B)LinkedList (C)HashSet (D) HashMap14、java中用来抛出异常的关键字是( )。()try ()catch ()throw ()throws15.关于finally块中的代码,以下说法不正确的是( )。(A)try块中的return语句会中断finally块中语句的执行(

5、B)无论finally块前的语句运行是否产生异常,其中的语句都会执行(C)finally块中的语句通常中用作资源的清理()try块中的System.exit(1)语句会中断finally块中语句的执行16.关于Java字符串说法错误的是( )。()Java中的字符串是常量 ()Java中的字符串不是对象()Java中的字符串存储在常量池中 ()一个字符串定义后的长度不可变17.关于JDBC操作数据库,以下说法不正确的( )。 ()JDBC只能操作MySQL数据库()JDBC中定义的Connection,Statement,ResultSet都是接口()JDBC操作数据库必须要有相应的实现了JD

6、BC接口的驱动()JDBC可以通过将客户端的SQL传递给数据库服务器来实现数据库的操作18.以下程序代码错误的是( )。abstract class Pclass A extends Pabstract class B extends P()P p=new A();()P p=new B();()A a=new A();()P p=new P()void foo();19.以下ollection c创建有误的是( )。()Collection c=new ArrayList();()Collection c=new LinkedList();()Collection c=new HashSet

7、();()Collection c=new HashMap();20. 以下程序代码错误的是( )。interface IA void f();()abstract class A implements IA ()class A implements IAvoid f()()class A implements IAvoid f(String s) ()IA a=new IA()void f()得分阅卷人二、程序阅读(每题 5分,共 20分)21.阅读程序,并写出程序运行结果public class T21 static int init() System.out.println(A); re

8、turn 0; static boolean test(int i) System.out.println(B); return i1; static int add(int i) System.out.println(C); return +i; public static void main(String args) for(int t=init();test(t);t=add(t) System.out.println(D); 22.阅读程序,并写出程序运行结果class TObject TObject() System.out.println(A); void m(String s)

9、System.out.println(B); void m(int i) System.out.println(C); void m() System.out.println(D); public String toString() return E; public class T22 public static void main(String args) TObject obj=new TObject(); System.out.println(obj); obj.m(); obj.m(1); obj.m(1); 23 阅读程序,并写出程序运行结果abstract class P P()

10、System.out.println(P); abstract void goo();class A extends P A() super(); void goo() System.out.println(A); void foo() System.out.println(F); class B extends P void goo() System.out.println(B); void koo() System.out.println(K); public class T23 public static void main(String args) A a=new A(); a.goo

11、(); a.foo(); B b=new B(); b.koo(); 24 阅读程序,并写出程序运行结果interface IT void t1(); void t2();abstract class TA implements IT public void t1() System.out.println(A); public void t3() System.out.println(B); class TB extends TA public void t1() System.out.println(C); public void t2() System.out.println(D); pu

12、blic void t2(int i) System.out.println(E); public class T24 public static void main(String args) IT obj=new TB(); obj.t1(); obj.t2(); TA aObj=(TA)obj; aObj.t1(); aObj.t3(); TB bObj=(TB)obj; bObj.t2(100); 得分阅卷人三、程序填空(每空2分,共 20分)程序一:如下程序测试Math.random生成随机数的奇偶比率,仔细阅读程序和运行结果,补全空白处的代码。/* * 测试Math.random生成

13、随机数的奇偶比率 */public class T25 /* * 生成给定数量的到1000随机整数,并把生成的随机存入到一个int数组中 * param int count要生成的随机数量 * return int 生成的随机数存储数组 */ int createArray(int count) int number= (25) ; /创建长度为count的int数组 for(int i=0;icount;i+) int n=(int)(Math.random()*1000); numberi= (26) ;/在number数组中写入生成的随机数 System.out.println(numb

14、er+i+=+numberi); return (27) ; /返回生成的数组 /* *计算给定数组的奇数的比率 *param int number要计算的数组 *return double 奇数的比率 */ double calculateOddRate(int number) int count=(28) ; /读取数组元素的个数,即要计算平均数的整数个数 double odd=0;/奇数计数 for(int n:number) if( (29) )/如果n是奇数,奇数计数加 odd+; return odd/count; public static void main(String ar

15、gs) T25 t=new T25(); int number=t.createArray(100); double oddRate=t.calculateOddRate(number); System.out.println(奇数为:+oddRate*100+%); System.out.println(偶数为:+(1-oddRate)*100+%); 运行结果:number0=907./此处省略98行number99=598奇数为:52.0%偶数为:48.0%程序二: 以下程序是通过JDBC读取数据表Student的基本操作,认真阅读程序和运行结果,补全程序的空白处。表:StudentsI

16、DNAMEGENDER2name02女4name04女部分程序如下class Student private int id; private String name; private String gender; public Student(int id, String name, String gender) super(); this.id = id; this.name = name; this.gender = gender; /此处省略n行 public String toString() return Student id= + id + , name= + name + , g

17、ender= + gender+ ; public class T30 /*取得数据库连接*/ Connection getConnection() /此处省略n行 /* 查询数据库中所有学生的数据,将一条学生信息记录转化成一个Studetn对象, * 多个记录生成多个Student,将生成的对象放入到List中,一起返回到 */ List queryAllStudent() List stuList= (30) ;/创建可以存储Student的List Connection conn=null; Statement st=null; ResultSet rs=null; try conn=g

18、etConnection(); st= (31) .createStatement(); /通过连接创建statement rs=st.executeQuery(SELECT ID,NAME,GENDER FROM Students); while( (32) ) /结果是否有记录 Student stu=new Student( rs.getInt(ID), rs.getString(NAME), rs.getString(GENDER); (33) ; /把stu对象加入到stuList中 catch (SQLException e) e.printStackTrace(); finall

19、y try rs.close(); st.close(); conn.close(); catch (SQLException e) return stuList; /*显示List中的学生 */ void showStudent(List stuList) for(_(34)_s:stuList) /指明s的类型 System.out.println(s); public static void main(String args) T30 demo=new T30(); List stuList=demo.queryAllStudent(); demo.showStudent(stuList

20、); 运行结果Student id=2, name=Name02, gender=女Student id=4, name=Name04, gender=女得分阅卷人四、基本代码编写(共12分)35、(5分)编写一个main方法,计算如下数组元素的平均值 double source=2,5,9,10,3;36、(分)文件名解析器,仔细阅读如下代码和运行结果,完成WindowsFileNameParse类的代码,执行后得到给定的运行结果。interface FileNameParse void showSourceFileName(); String getDiskName(); String g

21、etFullFileName(); String getFileName(); String getExtendName(); String getDir(); class WindowsFileNameParse implements FileNameParse private String fileName; WindowsFileNameParse(String fileName) this.fileName=fileName; public void showSourceFileName() System.out.println(解析文件名:+this.fileName); / /请完

22、成此类的中其他方法的代码/public class T36 public static void main(String args) FileNameParse fp=new WindowsFileNameParse(d:/My Documents/MyJob/Pages/2012-2013-2/PageA/src/T37.java); fp.showSourceFileName(); System.out.println(盘符:+fp.getDiskName(); System.out.println(文件全名(带扩展名):+fp.getFullFileName(); System.out.

23、println(文件名(不带扩展名):+fp.getFileName(); System.out.println(文件扩展名:+fp.getExtendName(); System.out.println(路径(不带盘符):+fp.getDir(); 运行结果解析文件名:d:/My Documents/MyJob/Pages/2012-2013-2/PageA/src/T37.java盘符:d文件全名(带扩展名):T37.java文件名(不带扩展名):T37文件扩展名:java路径(不带盘符):/My Documents/MyJob/Pages/2012-2013-2/PageA/src附 S

24、tring类部分的api docpublic int indexOf(String str)Returns the index within this string of the first occurrence of the specified substring. Examples: abca.indexOf(a) return 0Parameters:str - the substring to search for.Returns:the index of the first occurrence of the specified substring, or -1 if there i

25、s no such occurrence.public int lastIndexOf(String str)Returns the index within this string of the last occurrence of the specified substring. The last occurrence of the empty string is considered to occur at the index value this.length(). Examples: abca.lastIndexOf(a) return 3Parameters:str - the s

26、ubstring to search for.Returns:the index of the last occurrence of the specified substring, or -1 if there is no such occurrence.public String substring(int beginIndex)Returns a new string that is a substring of this string. The substring begins with the character at the specified index and extends

27、to the end of this string. Examples: Harbison.substring(3) returns bisonemptiness.substring(9) returns (an empty string) Parameters:beginIndex - the beginning index, inclusive.Returns:the specified substring.public String substring(int beginIndex, int endIndex)Returns a new string that is a substring of this string. The substring begins at the specified beginIndex and extends to the character at index endIndex - 1. Thus the length of the substring is endIndex-beginIndex. Examples: hamburger.substring(4, 8

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1