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

上传人:tireattitude366 文档编号:1326471 上传时间:2019-10-17 格式:DOC 页数:5 大小:36.50KB
下载 相关 举报
【计算机类职业资格】二级JAVA机试-144及答案解析.doc_第1页
第1页 / 共5页
【计算机类职业资格】二级JAVA机试-144及答案解析.doc_第2页
第2页 / 共5页
【计算机类职业资格】二级JAVA机试-144及答案解析.doc_第3页
第3页 / 共5页
【计算机类职业资格】二级JAVA机试-144及答案解析.doc_第4页
第4页 / 共5页
【计算机类职业资格】二级JAVA机试-144及答案解析.doc_第5页
第5页 / 共5页
亲,该文档总共5页,全部预览完了,如果喜欢就下载吧!
资源描述

1、二级 JAVA 机试-144 及答案解析(总分:100.00,做题时间:90 分钟)一、1基本操作题(总题数:1,分数:33.00)1.System.out.println(“length:“+file2_1._ );(分数:33.00)_二、2简单应用题(总题数:1,分数:33.00)2.请完成下列 Java 程序:运行 3 个线程,每一个线程有自己的标志,用 a,b,c 表示,每个线程显示一个“Start”信息和一个“End”信息并且间隔地显示 2 个“Loop”信息(间隔变化为(0.5-2)秒之间的随机延迟)。程序运行结果如下:(注:由于时间间隔为随机数,所以,运行结果的顺序不惟一)a

2、Startb Startc Startb Loopa Loopb Loopb Endc Loopa Loopa Endc Loopc End注意:请勿改动 main()主方法和其他已有语句内容,仅在下划线处填入适当的语句。public class ex2_2 implements Runnable static char flag2_2 = a;public static void main(String arg) ex2_2 obj2_2 = new ex2_2();Thread thread2_2 = new Thread(obi2_2);thread2_2.start();thread2

3、2 = new Thread(obj2_2);thread2 2.start();thread2_2 = new Thread(obi2_2);thread2_2.start ( );public void run() char myflag2_2;synchronized(this) _;System.out.println(myflag2_2 +“ Start“);for(int i=0; i2; i+) try Thread.sleep(rand(500,2000);System.out.println(myflag2_2 +“ Loop“);catch(InterruptedExce

4、ption ie) System.out.println(ie);System.out.println(myflag2_2 +“ End“);final private int rand(int low, int high)return(_);(分数:33.00)_三、3综合应用题(总题数:1,分数:34.00)3.下面是一个 Applet 程序,其功能是有 2 个按钮,分别为 First 和 Second,以及一个 Labe1 构件。要求点击 First 时则能在 Labe1 中显示出 Command:First,而点击 Second 时则能显示出 Command:Second,要求只能使用

5、重载一次 actionPerformed()方法。请改正程序中的错误(有下划线的语句),使程序能输出正确的结果。注意:不改动程序的结构,不得增行或删行。程序运行结果如下:(分数:34.00)_二级 JAVA 机试-144 答案解析(总分:100.00,做题时间:90 分钟)一、1基本操作题(总题数:1,分数:33.00)1.System.out.println(“length:“+file2_1._ );(分数:33.00)_正确答案:(getName()getPath()length()解析:解析本题主要考查 Java 文件以及 Java 类库中的 File 类的常用方法。解题关键是熟记 J

6、ava 的 File 类的常用方法:getName(), getPath(),length()等。在本题中,这 3 个空分别对应填入这 3 个方法即可。二、2简单应用题(总题数:1,分数:33.00)2.请完成下列 Java 程序:运行 3 个线程,每一个线程有自己的标志,用 a,b,c 表示,每个线程显示一个“Start”信息和一个“End”信息并且间隔地显示 2 个“Loop”信息(间隔变化为(0.5-2)秒之间的随机延迟)。程序运行结果如下:(注:由于时间间隔为随机数,所以,运行结果的顺序不惟一)a Startb Startc Startb Loopa Loopb Loopb Endc

7、Loopa Loopa Endc Loopc End注意:请勿改动 main()主方法和其他已有语句内容,仅在下划线处填入适当的语句。public class ex2_2 implements Runnable static char flag2_2 = a;public static void main(String arg) ex2_2 obj2_2 = new ex2_2();Thread thread2_2 = new Thread(obi2_2);thread2_2.start();thread2_2 = new Thread(obj2_2);thread2 2.start();th

8、read2_2 = new Thread(obi2_2);thread2_2.start ( );public void run() char myflag2_2;synchronized(this) _;System.out.println(myflag2_2 +“ Start“);for(int i=0; i2; i+) try Thread.sleep(rand(500,2000);System.out.println(myflag2_2 +“ Loop“);catch(InterruptedException ie) System.out.println(ie);System.out.

9、println(myflag2_2 +“ End“);final private int rand(int low, int high)return(_);(分数:33.00)_正确答案:(myflag2_2 = flag2_2+(int)(high-low+1)*(Math.random()+low)解析:解析本题主要考查线程的创建与同步和控制随机数产生范围的算法。解题关键是,熟悉线程的概念和使用,线程的同步控制, char 类型数据的操作,以及熟悉随机数产生的方法 Math.random(),并且能够进一步根据需要控制随机数产生的范围。在本题中,main()方法中创建 3 个线程,这 3

10、个线程使用 obj2_2 对象。线程调用 start()方法来中断,使一个新的线程开始执行,并且调用 run()方法。第 1 空,run()方法为自己设置一个线程的标志,并为下一个线程的使用增加这个标志值,由于此时线程正在处理中,因此在同步块中完成修改标志的语句放在同步块中。第 2 个空,通过 low 和 high 两个参数,控制产生随机数的范围,将基本的数学思想应用于程序设计中。三、3综合应用题(总题数:1,分数:34.00)3.下面是一个 Applet 程序,其功能是有 2 个按钮,分别为 First 和 Second,以及一个 Labe1 构件。要求点击 First 时则能在 Labe1

11、 中显示出 Command:First,而点击 Second 时则能显示出 Command:Second,要求只能使用重载一次 actionPerformed()方法。请改正程序中的错误(有下划线的语句),使程序能输出正确的结果。注意:不改动程序的结构,不得增行或删行。程序运行结果如下:(分数:34.00)_正确答案:(btn.addActionListener(this)btn.setActionCommand(“second“)1setText(str)解析:解析本题主要考查 Java 语言中高级事件 ActionEvent 和 AWT 基本构件 Label 的常用方法的使用。解题关键是熟练掌握动作事件 ActionEvent 和 Label 构件的常用方法。在本题中,第 1 处,明确注册的事件监听器是监听按钮的,而不是 Label 的;第 2 处,调用 ActionEvent 的 setActionCommand()方法改变了ActionCommand,使按下第二个按钮时显示 Command:second 而不是 Command:First。第 3 处,调用Label 的 setText()方法,而不是 Button 的方法。

展开阅读全文
相关资源
猜你喜欢
  • GOST R 22 0 03-1995 Safety in emergencies Natural emergencies Terms and definitions《紧急情况时的安全性 自然突发事件 术语和定义》.pdf GOST R 22 0 03-1995 Safety in emergencies Natural emergencies Terms and definitions《紧急情况时的安全性 自然突发事件 术语和定义》.pdf
  • GOST R 22 0 04-1995 Safety in emergencies Biologist social emergencies Terms and definitions《紧急情况时的安全性 生物学家社会突发事件 术语和定义》.pdf GOST R 22 0 04-1995 Safety in emergencies Biologist social emergencies Terms and definitions《紧急情况时的安全性 生物学家社会突发事件 术语和定义》.pdf
  • GOST R 22 0 05-1994 Safety in emergencies Technogenic emergencies Terms and definitions《紧急情况时的安全性 技术突发事件 术语和定义》.pdf GOST R 22 0 05-1994 Safety in emergencies Technogenic emergencies Terms and definitions《紧急情况时的安全性 技术突发事件 术语和定义》.pdf
  • GOST R 22 0 06-1995 Safety in emergencies The sources of natural emergencies Injuring factors Nomenclature of parameters of injuring influences《紧急情况时的安全性 自然突发事件的原因 损伤原因 损伤影响参数的名称》.pdf GOST R 22 0 06-1995 Safety in emergencies The sources of natural emergencies Injuring factors Nomenclature of parameters of injuring influences《紧急情况时的安全性 自然突发事件的原因 损伤原因 损伤影响参数的名称》.pdf
  • GOST R 22 0 07-1995 Safety in emergencies The sources of technogenic emergencies Classification and enumeration of casualty factors and its parameters《紧急情况时的安全性 技术突发事件原因 伤亡因素和其参数的分.pdf GOST R 22 0 07-1995 Safety in emergencies The sources of technogenic emergencies Classification and enumeration of casualty factors and its parameters《紧急情况时的安全性 技术突发事件原因 伤亡因素和其参数的分.pdf
  • GOST R 22 0 08-1996 Safety in emergencies Technogenic emergencies Terms and definitions《紧急情况时的安全性 技术突发事件 术语和定义》.pdf GOST R 22 0 08-1996 Safety in emergencies Technogenic emergencies Terms and definitions《紧急情况时的安全性 技术突发事件 术语和定义》.pdf
  • GOST R 22 0 09-1995 Safety in emergencies Emergencies on the water surface Terms and definitions《紧急情况时的安全性 水面上的突发事件 术语和定义》.pdf GOST R 22 0 09-1995 Safety in emergencies Emergencies on the water surface Terms and definitions《紧急情况时的安全性 水面上的突发事件 术语和定义》.pdf
  • GOST R 22 0 11-1999 Safety in emergencies Forecasting of natural emergency situations Terms and definitions《紧急情况时的安全性 自然突发情况预测 术语和定义》.pdf GOST R 22 0 11-1999 Safety in emergencies Forecasting of natural emergency situations Terms and definitions《紧急情况时的安全性 自然突发情况预测 术语和定义》.pdf
  • GOST R 22 1 01-1995 Safety in emergencies Monitoring and forecasting Basic principles《紧急情况时的安全性 监控和预测 基本原则》.pdf GOST R 22 1 01-1995 Safety in emergencies Monitoring and forecasting Basic principles《紧急情况时的安全性 监控和预测 基本原则》.pdf
  • 相关搜索

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

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