Java6程序设计实践教程课后答案_清华大学出版社_第1页
Java6程序设计实践教程课后答案_清华大学出版社_第2页
Java6程序设计实践教程课后答案_清华大学出版社_第3页
Java6程序设计实践教程课后答案_清华大学出版社_第4页
Java6程序设计实践教程课后答案_清华大学出版社_第5页
已阅读5页,还剩4页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、第1章:参考答案:习题集:一、 填空题1多态2java.exe3jdb.exe4标准字节码5java6独立于平台二、选择题1b2a3b4a5a6c7c8d9c第2章:参考答案:实验指导:2.5.1第一处需要的代码:yourguess>realnumber第二处需要的代码:yourguess=input.nextint();第三处需要的代码:yourguess<realnumber第四处需要的代码:yourguess=input.nextint();2.5.2第一处需要的代码:iarrayi < iarrayj第二处需要的代码:itemp = iarrayi; iarrayi

2、= iarrayj; iarrayj = itemp;2.5.3第一处需要的代码:continue lable;第二处需要的代码:system.out.print(" "+(i+j);2.5.4第一处需要的代码:system.out.print("t");第二处需要的代码:system.out.print(j + "*" + i + "=" + (i*j) + "t");习题集:一、填空题1i=i+1 sum=sum+1 i<1002while do while for 394the sy

3、mbol is an a.the symbol is a b.the symbol is c.the symbol is not a,b,or c.switch is completed5sum=0 pos+二、选择题 1d2a3d4a 5d6a7b8b9c三、简答题 2there is no this value 3message four i is 1,2,3 i is 1,2,3 i is 1,2,3 i is 4第3章参考答案:实验指导:3.10.1第一处需要的代码:balance+=saveaccount;第二处需要的代码:balance+=calculateinterst(days

4、);第三处需要的代码:ba.setmoney(save_value);ba.setinterstrate(interst_rate);第四处需要的代码:ba.accountinterst(365);3.10.2第一处需要的代码:minute=this.m_minute;second=this.m_second;第二处需要的代码:s=d.getminutes()+":"+d.getseconds()+":"+d.gettime();3.10.3第一处需要的代码:super(number,pass);balance=bal;第二处需要的代码:connect3

5、.10.4第一处需要的代码:super(pass, motor);this.make=make;this.model=model;第二处需要的代码:am.run();习题集:一、填空题1类2代码和数据3点4实例变量5test te=new test();6对象实例化7值、引用8the original is data is:-1now the data is:109i am parenti am childi am child二、选择题 1b 2a 3c 4c 5a 6a 7c 8a 9d 10c 11a 12c 13c三、简答题 6 a abstract和final修饰符不能同时使用b 未给

6、出类型定义,final int max_number=10;c 常量不能修改d 静态方法值能访问静态变量,static int data。或者把方法标志为非静态方法,int getdata()e 构造方法无返回值,把void去掉f 抽象类不能进行实例化,把abstract去掉g 子类不能继承父类的私有成员,应把parent类中的mine属性的private修饰符去掉。h 父类对象不能与之类形式参数结合,可以颠倒过来。如下代码所示:class parent int mine;class child extends parentint mine;class usechildstatic int g

7、etmine(parent p)return(p.mine);public static void main(string args) child c=new child();system.out.println(usechild.getmine(c);第4章答案: 实验指导4.5.1第一处需要的代码:public void print()system.out.println("hello");yourguess>realnumber第二处需要的代码:hello h = new hello(); h.print();4.5.2第一处需要的代码:public void

8、stop() system.out.println("network stop!");第二处需要的代码:public void start() system.out.println("du du."); 第三处需要的代码:soundcard sc=new soundcard(); mb.usepcicard(sc);4.5.3第一处需要的代码:this.useraccount = acc; this.userpassword = pass;第二处需要的代码:public void show() system.out.println(resultmessa

9、ge); 第三处需要的代码:user.connect();user.show();填空题1javac d . test.java2package3public4package com.my.test; public void input()system.out.println("n hi,keybroad has be input into then mainbroad!n"); public void input()system.out.println("n hi,netcardbroad has be input into then mainbroad!n&q

10、uot;); publicvoid getmainmessage(extendbroadable ext)ext.input();5constants.max_count6interface b extends apublic void printb();选择题1c2d3b4c5b6c7c8b9d10d11d12a简答(1) 1、接口是类似于类的结构,它只包含常量和抽象方法。在某些情况下,接口类似于抽象类,但是抽象类能够包含常量和抽象方法,还能够包含变量和具体方法。(2) 1、在接口中,数据可以是常量;而抽象类可以有数据字段。2、在接口中方法只有无实现的签名,而抽象类可以有具体的方法。3、因为

11、定义在接口中的所有方法都是抽象方法,java不要求将抽象修饰符放在4、接口中的方法签名中,但是在抽象类中要将抽象修饰符放在抽象方法之前。(3) 1、可以更好的组织类。2、减少类名的冲突问题,同一包中的类名不能重复,不同包中的类名可以重复;3、对包中的类起了一定的保护作用;(4) 1、直接引用指定的类,如import java.util.vector;2、引用一个包中的多个类,如import java.awt.*。更确切的说,它并不是引用java.awt中的所有类,而只引用定义为public的类,并且只引用被代码引用的类,所以这种引用方法并不会降低程序的性能;3、*号代替类名,在不能代替包名,如

12、import java.awt.*,只引用java.awt下的类,而不引用java.awt下的包;4、import java.awt.f*,这种使用方法是错误的;5、import语句在所有类定义之前,在package定义之后;6、import只告诉编译器及解释器哪里可以找到类、变量、方法的定义,而并没有将这些定义引入代码中;第5章参考答案:实验指导:5.6.1第一处需要填写的代码:i<st.length()第二处需要填写的代码:st.indexof("you")5.6.2第一处需要填写的代码:int i=0;i<a.length;i+;第二处需要填写的代码:ai

13、=(char)(ai't');5.6.3第一处需要填写的代码:nowtime第二处需要填写的代码:matter1.format(nowtime)5.6.4第一处需要填写的代码:int i=0;i<days;i+第二处需要填写的代码:i%7=0习题集:二、 填空题1equalsignorecase2helloi like java!3char值4java.util.date5hello!6false7a#a#a#8xyz3459int len=str.length();c>='a'&&c<='z'i+;10i=0;

14、i<str.length();i+;int temp=str.charat(i);sum+;二、选择题1b2a3a4b5d6a7b8d三、简答题1字符串的容量是:28用过setlength(200)后字符串的长度是:200使用了charat(2):w2中国:the money is: ¥30,215.00the number is: 121.666673good and gbc4strawberry plum persimmon pear peach peach orange grape fig banana apple第6章答案实验指导6.4.1第一处需要的代码:number1 = i

15、nteger.parseint( firstnumber); number2= integer.parseint( secondnumber);yourguess>realnumber第二处需要的代码:numberformatexception ex 6.4.2第一处需要的代码:catch(ioexception e)system.out.println("catch "+e.tostring(); 第二处需要的代码:catch(numberformatexception e)system.out.println("catch "+e.tostri

16、ng(); 填空题:1welcome to javathe finally clause is executed2welcome to javathe finally clause is executed3catch(numberformatexception e)4仍然执行5arithmeticexception6ioexception7数据转换错误异常8statement1,statement2二、选择题 1c2b3c4d5c6b7c第7章参考答案:实验指导:7.7.1第一处需要填写的代码:panel.setvisible(true);第二处需要填写的代码:group.add(radiob

17、utton1); group.add(radiobutton2);第三处需要填写的代码:mainpanel.add(panel);7.7.2第一处需要填写的代码:commenttabpane = new jtabbedpane();第二处需要填写的代码:tabaddcomponent.add(namelabel);第三处需要填写的代码:querycom();7.7.3第一处需要填写的代码:system.exit(0);第二处需要填写的代码:new counter(); 7.7.4第一处需要填写的代码:setvisible(true);第二处需要填写的代码:frame.getcontentpan

18、e().add(new jtextarea();习题集:三、 填空题1btni=new jbutton(strnamei); borderlayout.east、borderlayout.west、borderlayout.south、borderlayout.north、borderlayout.center2frame.setcontentpane(new calculatorpanel().createpane();int y = 0; y < 4; y+、button = new jbutton(lablesyx);3frame.getcontentpane().add(new

19、treepanel().createcomponent();node01.add(node0102); int i = 0; i < names.length; i+、panel.add(new jlabel(namesi);4jframe.setvisible(true); container contentpane=jframe.getcontentpane();text.append(s);5container contentpanel = frame.getcontentpane(); frame.setvisible(true); add(part2(); panel.setv

20、isible(true);6panel pan=new panel();二、选择题1d2a3b4b5a6d7c第8章参考答案:实验指导:8.6.1第一处需要的代码:contentpane.addmouselistener(this);contentpane.addmousemotionlistener(this);第二处需要的代码:g.drawline(startx,starty,endx,endy);8.6.2第一处需要的代码:container contentpane = f.getcontentpane();第二处需要的代码:(e.getactioncommand().equals(&q

21、uot;按我有声音喔")8.6.3第一处需要的代码:treemodel.insertnodeinto(leafnode,node1,node1.getchildcount();第二处需要的代码:e.getsource()=tree8.6.4第一处需要的代码:b0.addactionlistener(new bt();第二处需要的代码:x=double.parsedouble(tf1.gettext().trim();习题集:一、填空题1程序符号2授权事件模型3actionperformed(actionevent e),itemstatechanged(itemevent e)4事件

22、适配器5new windowadapter(),system.exit(0);二、选择题 1d 2c 3d 4b 5a 第9章参考答案:实验指导:9.4.1第一处需要填写的代码:g_2d.setstroke(bs);g_2d.setcolor(color.yellow);g_2d.draw(hourline);第二处需要填写的代码:secondline.setline(120,120,(int)pointsxa,(int)pointsya);9.4.2第一处需要填写的代码:signal.setred(0);signal.setyellow(1);第二处需要填写的代码:g.setcolor(co

23、lor.green);习题集:填空题:1drawstring2add(p1)3tostring(i)4public void paint(graphics g)5int count=1;count<xpoint.length;count+6public void init()选择题:1a2b3b4b第10章参考答案:实验指导:10.6.1第一处需要填写的代码:tempstr=bufreader.readline();第二处需要填写的代码:s*=i;10.6.2第一处需要填写的代码:fileprex = null第二处需要填写的代码:int j = 0; j < children.l

24、ength; j+10.6.3第一处需要填写的代码:instream,outstream第二处需要填写的代码:copybut,0,copylen10.6.4第一处需要填写的代码:tempstr=inobj.readline();习题集:一、填空题:1hello!i like java!2110 110 110 110 1103inputstreamreaderbufferedreaderreadline()4helloworld!5year%4=0&&year%100!=0|year%400=06string s="information to appendn mon

25、!n"二、选择题:1d2a3a4b5d6b7b8d第11章参考答案:实验指导:11.6.1第一处需要填写的代码:class.forname(dbdriver) ;conn = drivermanager.getconnection(dburl,dbuser,dbpassword) ;第二处需要填写的代码:conn = getconnection();stmt = conn.createstatement();第三处需要填写的代码:stmt.executeupdate("insert into t_test values('ew','dgf',

26、'dfg');"); stmt.executeupdate("insert into t_test values('dg','df','fdg');"); stmt.executeupdate("insert into t_test values('dfg','dfg','dfg');");stmt.executeupdate("insert into t_test values('gdf','df&

27、#39;,'df');");第四处需要填写的代码:stmt.executeupdate("delete from t_test;");11.6.2第一处需要填写的代码:pstmt=conn.preparestatement("insert into t_grade values(?,?,?);");pstmt.setstring(1,name);pstmt.setstring(2,course);pstmt.setstring(3,grade);pstmt.execute();第二处需要填写的代码:rs = stmt.executequery("select * from t_gra

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

最新文档

评论

0/150

提交评论