JAVA第9章第10章课后习题答案.doc

JAVA第9章第10章课后习题答案.doc

ID:57688506

大小:53.50 KB

页数:10页

时间:2020-09-01

JAVA第9章第10章课后习题答案.doc_第1页
JAVA第9章第10章课后习题答案.doc_第2页
JAVA第9章第10章课后习题答案.doc_第3页
JAVA第9章第10章课后习题答案.doc_第4页
JAVA第9章第10章课后习题答案.doc_第5页
资源描述:

《JAVA第9章第10章课后习题答案.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库

1、第9章多线程4、C5、D6、packagecn.ntu.zhanbin;publicclassThreadOutputimplementsRunnable{staticThreadOutputto=newThreadOutput();publicstaticvoidmain(String[]args){//创建两个线程Threadt1=newThread(newThreadOutput());Threadt2=newThread(newThreadOutput());t1.start();t2.start();}publicvoidrun(){

2、synchronized(to){to.print();}}voidprint(){for(inti=0;i<6;i++){System.out.print(10+i);if(i<5){System.out.print(",");}try{Thread.sleep(500);}catch(InterruptedExceptione){e.printStackTrace();}}System.out.println("");}}------------------------------------------------------------

3、---------8、packagecn.ntu.zhanbin;publicclassThreadAlphabetextendsThread{publicstaticvoidmain(String[]args){//创建3个线程ThreadAlphabetta1=newThreadAlphabet("线程1:");ThreadAlphabetta2=newThreadAlphabet("线程2:");ThreadAlphabetta3=newThreadAlphabet("线程3:");ta1.start();ta2.start();ta3.

4、start();}ThreadAlphabet(Stringname){super(name);//调用父类的构造函数}publicvoidrun(){//获取当前线程名Stringname=Thread.currentThread().getName();//输出for(inti=0;i<26;i++){System.out.println(name+(char)(i+65));try{Thread.sleep(200);}catch(InterruptedExceptione){e.printStackTrace();}}}}-------

5、--------------------------------------------------------------9、packagecn.ntu.zhanbin;publicclassPrintOddsimplementsRunnable{privateintbound;//创建一个静态PrintOdds对象,并设置边界范围为20staticPrintOddspo=newPrintOdds(20);publicPrintOdds(intb){bound=b;}publicvoidprint(){for(inti=1;i

6、+=2){System.out.println(i);}}publicvoidrun(){po.print();}publicstaticvoidmain(String[]args){Threadt=newThread(po);t.start();}}第10章数据库编程说明:课本中连接数据库和关闭数据库的操作都是调用的P201的例10-1的ConnectionManager,而书中的类只写了getConnection()方法,各个关闭操作的方法均未给出。因此为避免程序出错,故已将连接数据库操作和关闭操作都写入各题目的类中,以便直接调用。3、pa

7、ckagecn.ntu.zhanbin;importjava.sql.Connection;importjava.sql.DriverManager;importjava.sql.PreparedStatement;importjava.sql.SQLException;importjava.sql.Statement;publicclassInsertUser{privateConnectioncon;privatePreparedStatementpstmt;publicstaticvoidmain(String[]args){intres

8、ult=newInsertUser().insert("admin","11");if(result>0)System.out.println("插入

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。