[计算机类试卷]国家二级(JAVA)机试模拟试卷88及答案与解析.doc
《[计算机类试卷]国家二级(JAVA)机试模拟试卷88及答案与解析.doc》由会员分享,可在线阅读,更多相关《[计算机类试卷]国家二级(JAVA)机试模拟试卷88及答案与解析.doc(8页珍藏版)》请在麦多课文档分享上搜索。
1、国家二级( JAVA)机试模拟试卷 88及答案与解析 一、基本操作题( 30分) 1 本程序的功能是,从键盘输入一个整数,存入一个输入流中,然后输出它的两倍值。请将程序补充完整。 注意:请勿修改 main()主方法和其他已有语句内容,仅在横线处填入适当语句。 import java.io.*; public class basic public static void main(String args) File dir=new File(“.“); Filter filter=new Filter(“java“); System.out.println(“list java files in
2、 directory“ +dir); String files=dir.list(filter); /列出目录 dir下,文件后缀名为 java的所有文件 for(_;_;i+) File f=new File(dir,filesi); _ (f.isFile() /如果该对象为后缀为 java的文件,则打印文件名 System.out.println(“file“ +f); else System.out.println(“sub directory“ +f); /如果是目录则打印目录名 class Filter implements FilenameFilter String extent
3、; Filter(String extent) this.extent=extent; public boolean accept(File dir,String name) return name.endswith(“.“+extent);/返回文件的后缀名 二、简单应用题( 40分) 2 请完成程序,首先由一个类 simple实现 Serializable接口,并有三个成员变量,分别为 int型、 double型和 String型,可以用 toString的方法显示这三个成员变量。在 main方法中创建这个 simple的持久对象,根据用户在命令行输入的三个参数来设定其中成员变量的值。然后
4、,将这个对象写入名为 TheSerial.data的文件中, 并显示成员变量。最后从文件 TheSerial.data中读出三个成员变量并显示出来。 注意:请勿修改 main()主方法和其他已有语句内容,仅在横线处填入适当语句。 import java.io.*; class TheSerial implements Serializable private int intvalue; private double doublevalue; private String string; The Serial () intvalue=123; doublevalue=12.34; string=
5、“Serialize Test“; public void setDouble(double d) doublevalue=d; public void setInt(int i) intvalue=i; public void setString(String s) string=s; public String to String() return(“int=“+intvalue+“ double=“+doublevalue+“ string=“+string); public class simple public static void main(String args) The Se
6、rial e1=new TheSerial(); TheSerial e2; try e1.setInt(Integer.parseInt(args0); e1.setDouble(Double.parseDouble(args1); e1.setString(args2); catch(Exception e) e1.setString(e.getMessage(); System.out.println(e1); try FileOutputStream oS=new FileOutputStream(“TheSerial.data“); ObjectOutputStream oOS=ne
7、w ObjectOutputStream(oS); _; catch(IOException ioException) System.out.println (ioException.getMessage (); try FileInputStream iS=new FileInputStream(“TheSerial.data“); ObjectInputStream oIS=new ObjectInputStream(iS); _; System.out.println(e2); catch(IOException ioException) System.out.println(ioExc
8、eption.getMessage(); catch(ClassNotFoundException cnfException) System.out.println(cnfException.getMessage(); 三、综合应用题( 30分) 3 本题程序中实现了一个 “生产者一消费者问题 ”。生产者产生一个随机数存入DataPool类中,消费者从中取出数据。 DataPool类一次只能存放一个数据。请更正题中带下划线的部分。 注意:不改变程序的结构,不得增行或删行。 class DataPool private int data; private boolean isFull; publ
- 1.请仔细阅读文档,确保文档完整性,对于不预览、不比对内容而直接下载带来的问题本站不予受理。
- 2.下载的文档,不会出现我们的网址水印。
- 3、该文档所得收入(下载+内容+预览)归上传者、原创作者;如果您是本文档原作者,请点此认领!既往收益都归您。
下载文档到电脑,查找使用更方便
2000 积分 0人已下载
下载 | 加入VIP,交流精品资源 |
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 计算机 试卷 国家 二级 JAVA 模拟 88 答案 解析 DOC
