




已阅读5页,还剩5页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
- 1 - 复习题复习题 3 3 一、选择题一、选择题 1JDK 提供的编译器是( B ) 。 (A)java.exe(B)javac.exe (C)javap.exe(D)javaw.exe 2.以下作为 Java 程序入口的 main 方法声明正确的( C ) 。 (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.以下标识符错误的是( C ) 。 (A)Public(B)张三(C)class(D)main 4.java 中定义字符串 String s=”pzhu”,下面操作可以取得字符串长度的是( A ) 。 (A)s.length()(B)s.length(C)s.size()(D)length(s) 5.如下定义数组,操作正确的是(D ) 。 int a=1,2,3; (A)a3=100(B)a0.length(C)a+(D)a.length 6.如下定义二维数组操作错误的是() 。 int a=1,2,3; (A)a01=200(B)a0.length (C)a11=100(D)a.length 7. 以下数据类型存储空间最大的是(B) 。 (A)byte(B)long(C)float(D)char 8. 面向对象的三大特性,不包括如下 (A)。 (A)异常(B)封装(C)继承(D)多态 9、关于类的定义以下说法错误(B) 。 (A)类定义使用 class 关键字 (B)每个类中必须有一个 main 方法 (C)一个包可以包含多个类 (D)java 中所有类都是 Object 类的子类 10. 关于构造方法以下说法错误的是 (D)。 ()构造方法名必须与类名一致()构造方法可以重载 ()构造方法是通过 new 来调用()每个类都必须编写构造方法代码 11.关于继承如下说法错误的是(C) 。 ()Java 是单继承的()通过 extends 来定义继承 ()所有父类方法都可以被 override 的()继承呈现的是 is a 的关系 12. 以下代码执行的结果是(C)。 System.out.println(“攀枝花学院 pzhu“.length(); ()编译错误()运行错误()9()14 13. 用来存储键值对的容器是()。 (A)ArrayList(B)LinkedList(C)HashSet(D) HashMap 14、java 中用来抛出异常的关键字是(C) 。 ()try()catch()throw()throws 15.关于 finally 块中的代码,以下说法不正确的是(A) 。 (A)try 块中的 return 语句会中断 finally 块中语句的执行 (B)无论 finally 块前的语句运行是否产生异常,其中的语句都会执行 (C)finally 块中的语句通常中用作资源的清理 - 2 - ()try 块中的 System.exit(1)语句会中断 finally 块中语句的执行 16.关于 Java 字符串说法错误的是(B)。 ()Java 中的字符串是常量()Java 中的字符串不是对象 ()Java 中的字符串存储在常量池中()一个字符串定义后的长度不可变 17.关于 JDBC 操作数据库,以下说法不正确的() 。 ()JDBC 只能操作 MySQL 数据库 ()JDBC 中定义的 Connection,Statement,ResultSet 都是接口 ()JDBC 操作数据库必须要有相应的实现了 JDBC 接口的驱动 ()JDBC 可以通过将客户端的 SQL 传递给数据库服务器来实现数据库的操作 18.以下程序代码错误的是(B) 。 abstract class P classAextends P abstract class B extends P ()P p=newA();()P p=new B();()Aa=new A();()P p=new P()void foo(); 19.以下ollection c 创建有误的是(D) 。 ()Collection c=newArrayList();()Collection c=new LinkedList(); ()Collection c=new HashSet();()Collection c=new HashMap(); 20. 以下程序代码错误的是(C) 。 interface IA void f(); ()abstract classA implements IA ()classA implements IAvoid f() ()class Aimplements IAvoid f(String s) ()IAa=new IA()void f() 二、程序阅读二、程序阅读 21.阅读程序,并写出程序运行结果 public class T21 static int init() System.out.println(“A“); return 0; static boolean test(int i) System.out.println(“B“); return i queryAllStudent() List stuList=newArrayList();/创建可以存储 Student 的 List Connection conn=null; Statement st=null; ResultSet rs=null; try conn=getConnection(); st=conn.createStatement(); /通过连接创建 statement rs=st.executeQuery(“SELECT ID,NAME,GENDER FROM Students“); - 4 - while(rs.next() /结果是否有记录 Studentstu=new Student( rs.getInt(“ID“), rs.getString(“NAME“), rs.getString(“GENDER“); stuList.add(stu); /把 stu 对象加入到 stuList 中 catch (SQLException e) e.printStackTrace(); finally try rs.close(); st.close(); conn.close(); catch (SQLException e) return stuList; /*显示 List 中的学生 */ void showStudent(List stuList) for(_Student_s:stuList)/指明 s 的类型 System.out.println(s); public static void main(String args) T30 demo=new T30(); List stuList=demo.queryAllStudent(); demo.showStudent(stuList); 运行结果运行结果 Student id=2, name=Name02, gender=女 Student id=4, name=Name04, gender=女 四、基本代码编写四、基本代码编写 35、(5 分)编写一个 main 方法,计算如下数组元素的平均值 double source=2,5,9,10,3; 36、 (分)文件名解析器,仔细阅读如下代码和运行结果,完成 WindowsFileNameParse 类的代码, 执行后得到给定的运行结果。 interface FileNameParse void showSourceFileName(); String getDiskName(); String getFullFileName(); String getFileName(); String getExtendName(); - 5 - String getDir(); class WindowsFileNameParse implements FileNameParse private String fileName; WindowsFileNameParse(String fileName) this.fileName=fileName; public void showSourceFileName() System.out.println(“解析文件名:“+this.fileName); / /请完成此类的中其他方法的代码/ 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.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 附String类部分的api doc public int indexOf(String str) Returns the index within this string of the first occurrence of the specified substring. Examples:“abca“.indexOf(“a“)return 0 Parameters: str - the substring to search for. Returns: the index of the first occurrence of the specified substring, or -1 if there is 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 3 Parameters: - 6 - str - the substring 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 to the end of this string. Examples: “Harbison“.substring(3) returns “bison“ “emptiness“.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) returns “urge“ “smiles“.substring(1, 5) returns “mile“ Parameters: beginIndex - the beginning index, inclusive. endIndex - the ending index, exclusive. Returns: the specified substring. 五、设计并编程五、设计并编程 37、仔细阅读给定的代码和程序运行结果,完方法 size()、del()代码编写。 MyList 类是可以存储字符串对象的、基于链表的 List 的简单实现 class MyListNode String element; MyListNode nextNode = null; MyListNode(String element) this.element = element; class MyList private MyListNode firstNode = null; public void add(String element) /加入字符串到 MyList 中 MyListNode node = new MyListNode(element); if (firstNode = null) firstNode = node; else MyListNode lastNode = firstNode; while (lastNode.nextNode != null) - 7 - lastNode = lastNode.nextNode; lastNode.nextNode = node; public int size() /返回 MyList 中节点数 /完成此方法代码/ public String toArray() /将 MyList 中存储的所有字符串转化成 String int count = size(); if (count = 0) return null; String dest = new Stringcount; MyListNode lastNode = firstNode; int i = 0; do desti+ = lastNode.element;
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 查询任务调度优化-洞察及研究
- 强电专业考试题及答案解析
- 电子类专业试题及答案
- 高一专业测试题及答案
- 一例癌痛患者的个案护理
- 2025至2030中国中性防锈汽轮机油行业项目调研及市场前景预测评估报告
- 母婴护理风险防控策略课件
- 颌面部多发性骨折护理
- 2025至2030中国MicroBulk交付系统行业项目调研及市场前景预测评估报告
- 生态修复项目树木种植与生态修复效果评估承包合同
- 集成电路技术导论课件
- 交管12123学法减分试题库带答案
- 培育和践行社会主义核心价值观的课件
- 交通标志牌工程施工组织设计(标准版)
- 展筋丹-中医伤科学讲义-方剂加减变化汇总
- 第二章药物转运及转运体
- 全区建设工程质量检测人员岗位考试考核实施细则
- 【课件】《红烛》课件24张统编版高中语文必修上册
- 交通事故认定书复核申请书模板
- 装备外观代码
- “一机一档”范本(共12页)
评论
0/150
提交评论