【计算机类职业资格】二级JAVA机试-227及答案解析.doc

上传人:explodesoak291 文档编号:1326545 上传时间:2019-10-17 格式:DOC 页数:6 大小:39KB
下载 相关 举报
【计算机类职业资格】二级JAVA机试-227及答案解析.doc_第1页
第1页 / 共6页
【计算机类职业资格】二级JAVA机试-227及答案解析.doc_第2页
第2页 / 共6页
【计算机类职业资格】二级JAVA机试-227及答案解析.doc_第3页
第3页 / 共6页
【计算机类职业资格】二级JAVA机试-227及答案解析.doc_第4页
第4页 / 共6页
【计算机类职业资格】二级JAVA机试-227及答案解析.doc_第5页
第5页 / 共6页
点击查看更多>>
资源描述

1、二级 JAVA 机试-227 及答案解析(总分:100.00,做题时间:90 分钟)一、1基本操作题(总题数:1,分数:30.00)1.下面程序的功能是从键盘读取一行文本并将该文本存储到文件中。当用户运行该程序时,需要输入一行文本并按下回车键。然后在 DOS 系统提示符处输入 type file.txt 并按下 Enter 键,这时屏幕会显示type file.txt 的内容。通过这个命令可以验证该程序的功能。请在每条横线处填写一条语句,使程序的功能完整。注意:请勿改动 main()主方法和其他已有的语句内容,仅在横线处填入适当的语句。源程序文件代码清单如下:import java.io.*;

2、public class DoFilepublic static void main(String args)byte buffername=_80;trySystem.out.println(“/nEnter a line to be saved to disk:“);int bytesbleck= _;FileOutputStream f=new FileOutputStream(“file.txt“);_;catch(Exception e)e.printStackTrace();(分数:30.00)_二、2简单应用题(总题数:1,分数:40.00)2.请完成下列 Java 程序。程序的

3、功能是显示用户在命令行方式下指定的任意驱动器文件夹的内容。提示:public string()list();/将文件夹中所有文件名保存在字符数组中返回。注意:请勿改动 main()主方法和其他已有的语句内容,仅在下划线处填入适当的语句。源程序文件代码清单如下:import java.io.*;public class FindDirectoriespublic static void main(String args)if(args.length=0)args=new String()“;try_;String fileName=pathName.list();for(int i=0;ifil

4、eName.length;i+)File f=new File(pathName.getPath(),fileNamei);if(_)System.out.println(f.getCanonicalPath();main(new Stringf.getPath();catch(IOException e)e.printStackTrace();(分数:40.00)_三、3综合应用题(总题数:1,分数:30.00)3.下面是一个 Applet 程序,其功能是有两个按钮,分别为 First 和 Second,以及一个 Label 构件。要求单击 First 时能在 Label 中显示出“Comm

5、and:First“,而单击 Second 时能显示出“Command:Second“,要求只能重载一次 actionPerformed()方法,请改正程序中的错误(有下划线的语句),使程序能输出正确的结果。注意:不改动程序的结构,不得增行或删行。源程序文件代码清单如下:import java.awt.*;import java.awt.event.*;import java.applet.*;/*applet code=ex04_3.class width=800 height=400/applet*/Public class ex04_3 extends Applet implements

6、 ActionListenerprivate String str=“ok“;private Label l;private Button btn;public void init()setLayout(null);l=new Label(str);l.reshape(10,10,100,30);add(l);btn=new Button(“First“);btn.reshape(10,50,60,20);l.addActionListene(this);add(btn);btn=new Button(“Second“);btn.reshape(10,100,60,20);btn.setAct

7、ionCommand(“First“);btn.addActionListener(this);add(btn);public void actionPerformed(ActionEvent ae)str=“Command:“+ae.getActionCommand();btn.setText(str);ex04_3.htmlHTMLHEADTITLEex04_3/TITLE/HEADBODYapplet code=“ex2_3.class“ width=800 height=400/applet/BODY/HTML(分数:30.00)_二级 JAVA 机试-227 答案解析(总分:100.

8、00,做题时间:90 分钟)一、1基本操作题(总题数:1,分数:30.00)1.下面程序的功能是从键盘读取一行文本并将该文本存储到文件中。当用户运行该程序时,需要输入一行文本并按下回车键。然后在 DOS 系统提示符处输入 type file.txt 并按下 Enter 键,这时屏幕会显示type file.txt 的内容。通过这个命令可以验证该程序的功能。请在每条横线处填写一条语句,使程序的功能完整。注意:请勿改动 main()主方法和其他已有的语句内容,仅在横线处填入适当的语句。源程序文件代码清单如下:import java.io.*;public class DoFilepublic st

9、atic void main(String args)byte buffername=_80;trySystem.out.println(“/nEnter a line to be saved to disk:“);int bytesbleck= _;FileOutputStream f=new FileOutputStream(“file.txt“);_;catch(Exception e)e.printStackTrace();(分数:30.00)_正确答案:(new byteSystem.in.read(buffername)f.write(buffername,0,bytesblock

10、)解析:解析 本题主要考查基本数据类型、对文件的操作知识。解答本题的关键是熟练掌握基本数据类型、对文件的操作知识。在本题中,byte buffemame=byte100;语句的功能是定义含 100 个整型元素的数组 buffername, System.in.read(buffername);语句的功能是获得标准控制台的输入数据,f.write(buffemame,0, bytesblock)语句的功能是将从标准控制台获得的输入数据写入文件输出流中。二、2简单应用题(总题数:1,分数:40.00)2.请完成下列 Java 程序。程序的功能是显示用户在命令行方式下指定的任意驱动器文件夹的内容。提

11、示:public string()list();/将文件夹中所有文件名保存在字符数组中返回。注意:请勿改动 main()主方法和其他已有的语句内容,仅在下划线处填入适当的语句。源程序文件代码清单如下:import java.io.*;public class FindDirectoriespublic static void main(String args)if(args.length=0)args=new String()“;try_;String fileName=pathName.list();for(int i=0;ifileName.length;i+)File f=new Fil

12、e(pathName.getPath(),fileNamei);if(_)System.out.println(f.getCanonicalPath();main(new Stringf.getPath();catch(IOException e)e.printStackTrace();(分数:40.00)_正确答案:(File pathName=new File(args0)f.isDirectory()解析:解析 本题主要考查文件操作的基本知识。解答本题的关键是熟练掌握对文件操作的基本知识。其中,File pathName=new File(args0)语句的功能是生成 File 类对象

13、pathName; if(f.isDirectory()语句的功能是判断生成的 f 对象是否为文件夹。三、3综合应用题(总题数:1,分数:30.00)3.下面是一个 Applet 程序,其功能是有两个按钮,分别为 First 和 Second,以及一个 Label 构件。要求单击 First 时能在 Label 中显示出“Command:First“,而单击 Second 时能显示出“Command:Second“,要求只能重载一次 actionPerformed()方法,请改正程序中的错误(有下划线的语句),使程序能输出正确的结果。注意:不改动程序的结构,不得增行或删行。源程序文件代码清单如

14、下:import java.awt.*;import java.awt.event.*;import java.applet.*;/*applet code=ex04_3.class width=800 height=400/applet*/Public class ex04_3 extends Applet implements ActionListenerprivate String str=“ok“;private Label l;private Button btn;public void init()setLayout(null);l=new Label(str);l.reshape

15、10,10,100,30);add(l);btn=new Button(“First“);btn.reshape(10,50,60,20);l.addActionListene(this);add(btn);btn=new Button(“Second“);btn.reshape(10,100,60,20);btn.setActionCommand(“First“);btn.addActionListener(this);add(btn);public void actionPerformed(ActionEvent ae)str=“Command:“+ae.getActionCommand

16、);btn.setText(str);ex04_3.htmlHTMLHEADTITLEex04_3/TITLE/HEADBODYapplet code=“ex2_3.class“ width=800 height=400/applet/BODY/HTML(分数:30.00)_正确答案:(btn.addActionListener(this)btn.setActionCommand(“second“)l.setText(str)解析:解析 本题主要考查 Java 语言中高级事件 AcfionEvent 和 AWT 基本构件 Label 的常用方法的使用。解题关键是熟练掌握动作事件 ActionEvent 和 Label 构件的常用方法。在本题中,第 1 处,明确注册的事件监听器是监听按钮的,而不是 Label;第 2 处,调用 ActionEvent 的 setActionCommand()方法改变了 ActionCommand,使按下 Second 按钮时显示 “Command:second“,而不是“Command:First“;第 3 处,调用 Label 的 setText()方法,而不是 Button 的方法。程序运行结果如下图所示。

展开阅读全文
相关资源
猜你喜欢
  • KS X ISO IEC 24711-2007 Information technology-Office equipment-Method for determination of ink cartridge yield for color inkjet printers and multi-function devices that may contai.pdf KS X ISO IEC 24711-2007 Information technology-Office equipment-Method for determination of ink cartridge yield for color inkjet printers and multi-function devices that may contai.pdf
  • KS X ISO IEC 24712-2007 Information technology-Office equipment-Colour test pages for measurement of office equipment consumable yield《信息技术 测量办公设备耗材量用彩色试验纸》.pdf KS X ISO IEC 24712-2007 Information technology-Office equipment-Colour test pages for measurement of office equipment consumable yield《信息技术 测量办公设备耗材量用彩色试验纸》.pdf
  • KS X ISO IEC 24727-1-2008 Identification cards-Integrated circuit card programming interfaces-Part 1:Architecture《识别卡 集成电路卡程序设计接口 第1部分 结构》.pdf KS X ISO IEC 24727-1-2008 Identification cards-Integrated circuit card programming interfaces-Part 1:Architecture《识别卡 集成电路卡程序设计接口 第1部分 结构》.pdf
  • KS X ISO IEC 24730-1-2006 Information technology-Real Time Locating Systems(RTLS)-Part 1:Application Program Interface(API)《信息技术 实时定位系统(RTLS) 第1部分 应用程序接口(API)》.pdf KS X ISO IEC 24730-1-2006 Information technology-Real Time Locating Systems(RTLS)-Part 1:Application Program Interface(API)《信息技术 实时定位系统(RTLS) 第1部分 应用程序接口(API)》.pdf
  • KS X ISO IEC 24730-2-2006 Information technology-Real Time Locating System(RTLS)-Part 2:2 4 GHz air interface protocol《信息技术 实时定位系统(RTLS) 第2部分 直接序列扩频(DSSS)2 4 GHz远程接口协议》.pdf KS X ISO IEC 24730-2-2006 Information technology-Real Time Locating System(RTLS)-Part 2:2 4 GHz air interface protocol《信息技术 实时定位系统(RTLS) 第2部分 直接序列扩频(DSSS)2 4 GHz远程接口协议》.pdf
  • KS X ISO IEC 24730-5-2008 Information technology-Real time locating systems(RTLS)-Part 5:Chirp Spread Spectrum(CSS) at 2 4 GHz《信息技术 实时定位系统(RTLS) 第5部分 2 4GHz空中接口的调频扩频(CSS)》.pdf KS X ISO IEC 24730-5-2008 Information technology-Real time locating systems(RTLS)-Part 5:Chirp Spread Spectrum(CSS) at 2 4 GHz《信息技术 实时定位系统(RTLS) 第5部分 2 4GHz空中接口的调频扩频(CSS)》.pdf
  • KS X ISO IEC 24734-2010 Information technology-Office equipment-Method for measuring digital printing productivity《信息技术 办公设备 数码打印机速度的测量方法》.pdf KS X ISO IEC 24734-2010 Information technology-Office equipment-Method for measuring digital printing productivity《信息技术 办公设备 数码打印机速度的测量方法》.pdf
  • KS X ISO IEC 24735-2010 Information technology-Office equipment-Method for measuring digital copying productivity《信息技术 办公设备 数码复印机速度的测量方法》.pdf KS X ISO IEC 24735-2010 Information technology-Office equipment-Method for measuring digital copying productivity《信息技术 办公设备 数码复印机速度的测量方法》.pdf
  • KS X ISO IEC 24738-2008 Information technology-Icon symbols and functions for multimedia link attributes《信息技术 应用于多媒体连接属性的图标符号和功能》.pdf KS X ISO IEC 24738-2008 Information technology-Icon symbols and functions for multimedia link attributes《信息技术 应用于多媒体连接属性的图标符号和功能》.pdf
  • 相关搜索

    当前位置:首页 > 考试资料 > 职业资格

    copyright@ 2008-2019 麦多课文库(www.mydoc123.com)网站版权所有
    备案/许可证编号:苏ICP备17064731号-1