西南大学2014年《面向对象程序设计》第五次作业及答案.doc

西南大学2014年《面向对象程序设计》第五次作业及答案.doc

  1. 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
  2. 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  3. 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
[论述题] 1、阅读下面程序,并回答问题。 (1)try块中包含的哪些语句或表达式可能抛出异常? (2)流DataOutputStream和DataInputStream常被用于何种操作? (3)假定文件out.txt中原本没有任何数据,这段程序执行完成后,文件out.txt的内容是什么?程序在控制台窗口输出什么? import java.io.*; public class Test4 { ??????? public static void main(String args[]) { ??????????????? try { ??????????????????????? DataOutputStream dout = new DataOutputStream( ??????????????????????????????????????? new FileOutputStream(out.txt)); ??????????????????????? for (int i = 0; i 10; i++) ??????????????????????????????? dout.writeInt(0 + i); ??????????????????????? dout.close(); ??????????????????????? DataInputStream din = new DataInputStream( ??????????????????????????????????????? new FileInputStream(out.txt)); ??????????????????????? for (int i = 0; i 10; i++) ??????????????????????????????? System.out.print(din.readInt() - 0 + , ); ??????????????????????? din.close(); ??????????????? } catch (IOException e) { ??????????????????????? System.err.println(发生异常: + e); ??????????????????????? e.printStackTrace(); ??????????????? } ??????? } } 参考答案:问题(1):try块中下面的语句可能抛出异常: ? ?? ?? ?? ?? ?? ?? ?? ?? ? new??FileOutputStream(out.txt); ? ?? ?? ?? ?? ?? ?? ?? ?? ? dout.writeInt( 0 + i); ? ?? ?? ?? ?? ?? ?? ?? ?? ? dout.close( ); ? ?? ?? ?? ?? ?? ?? ?? ?? ? new??FileInputStream(out.txt); ? ?? ?? ?? ?? ?? ?? ?? ?? ?din.readInt( ) ? ?? ?? ?? ?? ?? ?? ?? ?? ???din.close( ); 问题(2):常被用于读取与存储(读写或输入/输出)基本数据类型的数据。 问题(3): ? ?? ?? ?? ?? ?? ?? ? 文件out.txt的内容是:0 1 2 3 4 5 6 7 8 9 ? ?? ?? ?? ?? ?? ?? ? 程序在控制台窗口输出:0,1,2,3,4,5,6,7,8,9, 2、阅读下面程序,并回答问题。 (1)Java程序分为哪两种类型,这段程序是哪一类Java程序? (2)这个图形用户界面上包含那几类组件?点击按钮后程序显示什么? (3)ActionListener是什么?程序中哪个方法是ActionListener中的方法?其功能是什么? import javax.swing.*; import java.awt.*;?????????????????????????? import java.awt.event.*; public class Test4 extends JApplet implements ActionListener{ ??????? private Container cp = getContentPane();; ??????? private JLabel prompt = new JLabel(请点击按钮);??????? ??????? private JButton? start = new JButton(开始); ??????? private JTextField output =

您可能关注的文档

文档评论(0)

好老师 + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档