




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、复习题3一、选择题1. JDKI供的编译器是(B)0(A) java.exe(B) javac.exe(。javap.exe(D) javaw.exe2 .以下作为Javari序入口的main方法声明正确的(C)。(A) public void main(String args口)(B) public int main(String args)(CC public static void main(String args)(D) public static int main(String args口)3 .以下标识符错误的是(C)o(A) Public (B)张三(。class(D) main
2、A)。4 .java中定义字符串String s='pzhu”,下面操作可以取得字符串长度的是(A) s.length()(B) s.length (Q s.size()(D) length(s)5 .如下定义数组,操作正确的是( D )0int a=1,2,3;(A) a3=100(B) a0.length (Q a+(D) a.length6 .如下定义二维数组操作错误的是(int a=1,2,3;(A) a01=200(B) a0.length (。a11=100(D) a.length7 .以下数据类型存储空间最大的是( B )0(A) byte (B) long(。float
3、(D) char8 .面向对象的三大特性,不包括如下(A )。(A)异常 (B)封装 (Q继承(D)多态9、关于类的定义以下说法错误( B )0(A)类定义使用clas业键字(B)每个类中必须有一个 main方法(C) 一个包可以包含多个类(D) java中所有类都是Object类的子类10.关于构造方法以下说法错误的是(D )。(A)构造方法名必须与类名一致(B)构造方法可以重载(C)构造方法是通过new来调用 (D)每个类都必须编写构造方法代码11关于继承如下说法错误的是(C )。(A) Javal!单继承的(B)通过extend冰定义继承(C)所有父类方法都可以被 override的 (
4、D)继承呈现的是is a的关系12 .以下代码执行的结果是(C )。页脚内容3System.out.println律枝花学院 pzhu".length();(A)编译错误(B)运行错误(C) 9(D) 1413 .用来存储键值对的容器是()(A) ArrayList(B) LinkedList (。HashSet(D) HashMap 14 java中用来抛出异常的关键字是(C )(A) try(B) catch(C) throw(D) throws15关于巾nally块中的代码,以下说法不正确的是( A )。(A) try块中的return语句会中断巾nally块中语句的执行(B)
5、无论汇nally块前的语句运行是否产生异常,其中的语句都会执行(C) finally块中的语句通常中用作资源的清理(D) try块中的System.exit(体句会中断finally块中语句的执行16关于Java字符串说法错误的是(B )。(A) Java中的字符串是常量(B) Java中的字符串不是对象(C) Java中的字符串存储在常量池中(D) 一个字符串定义后的长度不可变17关于JDBCM乍数据库,以下说法不正确的()。(A) JDBCR能操作MySQL据库(B) JDBC定义的 Connection,Statement,ResultSet1接口(C ) JDBCM乍数据库必须要有相应
6、的实现了JDB骏口的驱动(D) JDBCT以通过将客户端的SQ胺递给数据库服务器来实现数据库的操作18以下程序代码错误的是( B )。abstract class P。class A extends P。abstract class B extends P。(A) P p=new A();(B) P p=new B();(C) A a=new A();(D) P p=new P()void foo()。;19以下C ollection c创建有误的是( D )。(A) Collection c=new ArrayList()( B ) Collection c=new LinkedList()
7、;(C) Collection c=new HashSet();D) Collection c=new HashMap();20.以下程序代码错误的是( C )0interface IAvoid f();(A) abstract class A implements IA B ) class A implements IAvoid f()(C) class A implements IAvoid f(String s) D) IA a=new IA()void f()二、程序阅读System.out.println("D");21阅读程序,并写出程序运行结果 public
8、class T21 static int init()System.out.println("A");return 0;static boolean test(int i)System.out.println("B");return i<1;static int add(int i)System.out.println("C");return +i;public static void main(String口 args) 22.阅读程序,并写出程序运行结果class TObjectTObject()System.out.pri
9、ntln("A");void m(String s)System.out.println("B");void m(int i)System.out.println("C");void m()for(int t=init();test(t);t=add(t)页脚内容5System.out.println("D");P()页脚内容#System.out.println("P");abstract void goo();class A extends PA()super();void goo() Sy
10、stem.out.println("A");void foo()System.out.println("F");class B extends Ppublic 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");答:输出结果为:D C B23阅读程序,
11、并写出程序运行结果abstract class Pvoid goo() public static void main(String口 args) System.out.println("B");void koo()System.out.println("K");public class T23 答:P A F P K24阅读程序,并写出程序运行结果interface ITvoid t1();void t2();abstract class TA implements ITpublic void t1() A a=new A();a.goo();a.fo
12、o();B b=new B();b.koo();System.out.println("A")public void t3() System.out.println("B")class TB extends TA页脚内容7IT obj=new TB();obj.t1();obj.t2();TA aObj=(TA)obj;aObj.t1();aObj.t3();TB bObj=(TB)obj;bObj.t2(100);答:A E D C A Bpublic void t1() public static void main(String口 args) Sy
13、stem.out.println("C");public void t2() System.out.println("D");答:B C D C B Epublic void t2(int i) System.out.println("E");public class T24 三、程序填空程序一:如下程序测试 Math.random生成随机数的奇偶比率,仔细阅读程序和运行结果, 补全空白处的代码。/*测试Math.random成随机数的奇偶比率*/public class T25 /* 生成给定数量的0到1000随机整数,并把生成的随
14、机存入到一个int数组中* param int count要生成的随机数量* return int口生成的随机数存储数组* /int口 createArray(int count)int number=new intcount; / 创建长度为 count的 int 数组for(int i=0;i<count;i+)int n=(int)(Math.random()*1000); numberi= n ;/在number数组中写入生成的随机数System.out.println("number"+i+”="+numberi); return number;
15、/返回生成的数组/*计算给定数组的奇数的比率* param int口 number要计算的数组* return double 奇数的比率* /double calculateOddRate(int口 number)int count=number.length ; /读取数组元素的个数,即要计算平均数 的整数个数double odd=0; / 奇数计数for(int n:number)if( n%2=1)/如果n是奇数,奇数计数加1odd+;return odd/count;public static void main(String口 args) T25 t=new T25();int口 n
16、umber=t.createArray(100);double oddRate=t.calculateOddRate(number);System.out.println("J数为:"+oddRate*100+"%");System.out.println(偶数为:"+(1-oddRate)*100+"%");运行结果:number0=907./此处省略98行number99=598奇数为:52.0%偶数为:48.0%程序二:以下程序是通过JDB限取数据表Student的基本操作,认真阅读程序和运行结 果,补全程序的空白处。
17、表:StudentsIDNAMEGENDER页脚内容112name02女4name04女部分程序如下class Studentprivate int id;private String name;private String gender;public Student(int id, String name, String gender) super();this.id = id; = name;this.gender = gender;/此处省略n行public String toString() return "Student id=" + id +
18、", name=" + name + ", gender=" + gender+ ""public class T30 /*取得数据库连接*/Connection getConnection()/此处省略n行/*查询数据库中所有学生的数据,将一条学生信息记录转化成一个Studetn对象,*多个记录生成多个Student将生成的对象放入到List中,一起返回到*/List<Student> queryAllStudent()List<Student> stuList= new ArrayList<Stude
19、nt>();/ 仓U 建可以存储 Studen的 ListConnection conn=null;Statement st=null;ResultSet rs=null;try conn=getConnection();st=conn.createStatement(); A®过连接创建 statementrs=st.executeQuery("SELECT ID,NAME,GENDER FROM Students");while( rs.next() /结果是否有记录Student stu=new Student(rs.getInt("ID&q
20、uot;),rs.getString("NAME"),rs.getString("GENDER");stuList.add(stu);/ 把 stu对象加入至U stuList中 catch (SQLException e) e.printStackTrace();finallytry rs.close();st.close();conn.close();页脚内容13 catch (SQLException e) return stuList;/*显示List中的学生*/void showStudent(List<Student> stuLi
21、st)for( §tuden s:stuList) / 指明 s的类型System.out.println(s);public static void main(String口 args) T30 demo=new T30();List<Student> stuList=demo.queryAllStudent();demo.showStudent(stuList);运行结果Student id=2, name=Name02, gende疾Student id=4, name=Name04, gende疾四、基本代码编写35、(5分)编写一个main方法,计算如下数组元素
22、的平均值double source=2,5,9,10,3;36、( 7分)文件名解析器,仔细阅读如下代码和运行结果,完成 WindowsFileNameParse 类的代码,执行后得到给定的运行结果。interface FileNameParsevoid showSourceFileName();String getDiskName();String getFullFileName();String getFileName();String getExtendName();String getDir();class WindowsFileNameParse implements FileNam
23、eParseprivate 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
24、Documents/MyJob/Pages/2012-2013-2/PageA/src/T37.java");fp.showSourceFileName();System.out.println(B符:"+fp.getDiskName();System.out.println仪件全名(带扩展名):"+fp.getFullFileName();System.out.println仪件名(不带扩展名):"+fp.getFileName();System.out.println仪件扩展名:"+fp.getExtendName();System.out
25、.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 docpublic int indexOfString str)Returns the index within this strin
26、g of the first occurrence of the specified substring.Examples: "abca”.indexOf("a") return 0Parameters:str - the substring to search for.页脚内容17Returns: the index of the first occurrenceof the specified substring, or -1 if there is no such occurrence.public int lastIndexOString str)Retu
27、rns the index within this string of the last occurrence of the specified substring. The la occurrence of the empty string "" is considered to occur at the index value this.length().Examples: "abca".lastIndexOf("a") return 3Parameters:str - the substring to search for.Re
28、turns:the index of the last occurrenceof 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 a the specified index and extends to the end of this string.E
29、xamples:"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)Returnsa new string that
30、is a substringof this string. The substring beginsat the specified beginIndex and extends to the character at index endIndex - 1. Thus the length of the substring endIndex-beginIndex.Examples:"hamburger”.substring(4, 8) returns "urge""smiles”.substring(1,5) returns "mile&quo
31、t;Parameters:beginIndex - the beginning index, inclusive.endIndex - the ending index, exclusive.Returns:the specified substring.五、设计并编程页脚内容1937、仔细阅读给定的代码和程序运行结果,完方法 size() del()代码编写MyLis斐是可以存储字符串对象的、基于链表的List的简单实现class MyListNode String element;MyListNode nextNode = null;MyListNode(String element) t
32、his.element = element;class MyList private MyListNode firstNode = null;public void add(String element) / 加入字符串到 MyListMyListNode node = new MyListNode(element);if (firstNode = null) firstNode = node; else MyListNode lastNode = firstNode;while (lastNode.nextNode != null) lastNode = lastNode.nextNode;lastNode.nextNode = node;public int size() /返回 MyLis仲
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2024年国际美术设计师考试基础内容及答案
- 篮球模拟测试题及答案
- 助理广告师试题及答案知识架构
- 2024年助理广告师备考心得与实战经验分享试题及答案
- 植物辨识考试题及答案
- 2024年国际设计师考试的综合准备建议试题及答案
- 于设计教育中的广告设计课程建设探讨试题及答案
- 新材料在纺织品设计中的应用举例试题及答案
- 小升初舞蹈测试题及答案
- 北大竞赛数学试题及答案
- 商事仲裁协议合同模板
- 重庆征信有限责任公司招聘笔试题库2025
- 湖北省武汉市2025届高中毕业生四月调研考试政治试题及答案(武汉四调)
- 第三方人员管理制度(22篇)
- 篮球智慧树知到期末考试答案2024年
- 护理人员业务技术档案 模板
- 金融监管学-金融监管学课件
- 语文一年级上册:拼音9《y-w》ppt教学课件
- 标准溶液配制与标定原始记录(氢氧化钠)
- 内墙腻子施工技术交底
- 施工界面划分表(明细)
评论
0/150
提交评论