【计算机类职业资格】计算机二级(JAVA)上机考试28及答案解析.doc

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

1、计算机二级(JAVA)上机考试 28 及答案解析(总分:-3.00,做题时间:90 分钟)1.基本操作题 下列程序中,要求从键盘接受字符输入,直到输入字符为“e“(注意是小写)时停止,并且将输入的字符(“e“之前的字符)显示在屏幕上。请将程序补充完整。 程序运行结果如下: Keep typing, it will stop while enter e. ddfsofkjlvncozieowdsfadsf ddfsofkjlvncozi import java.io.*; public class ex4_1 public static void main(String args) char c

2、h; System.out.println(“Keep typing,it will stop while enter e.“); try while(ch= )!=e) System. ; catch(IOException ioe) System. ; (分数:-1.00)_2.简单应用题 请完成下列 Java 程序:运行 3 个线程,每一个线程有自己的标志,用 a,b,c 表示,每个线程显示一个“Start“信息和一个“End“信息并且间隔地显示 2 个“Loop“信息(间隔变化为(0.52)秒之间的随机延迟)。 程序运行结果如下:(注:由于时间间隔为随机数,所以,运行结果的顺序不惟一)

3、 a Start b Start c Start b Loop a Loop b Loop b End c Loop a Loop a End c Loop c 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(obj2_2); thread

4、2_2.start(); thread2_2 = new Thread(obj2_2); thread2_2.start(); thread2_2 = new Thread(obj2_2); thread2_2.start(); public void run() char myflag2_2; synchronized(this) ; System.out.println(myflag2_2 + “ Start“);for(int i=0; i_3.综合应用题 下面是一个 Applet 程序,其功能是有 2 个按钮,分别为 First 和 Second,以及一个 Label构件。要求点击 F

5、irst 时则能在 Label 中显示出 Command:First,而点击 Second 时则能显示出Command:Second,要求只能使用重载一次 actionPerformed()方法。请改正程序中的错误(有下划线的语句),使程序能输出正确的结果。程序运行结果如下: (分数:-1.00)_计算机二级(JAVA)上机考试 28 答案解析(总分:-3.00,做题时间:90 分钟)1.基本操作题 下列程序中,要求从键盘接受字符输入,直到输入字符为“e“(注意是小写)时停止,并且将输入的字符(“e“之前的字符)显示在屏幕上。请将程序补充完整。 程序运行结果如下: Keep typing, i

6、t will stop while enter e. ddfsofkjlvncozieowdsfadsf ddfsofkjlvncozi import java.io.*; public class ex4_1 public static void main(String args) char ch; System.out.println(“Keep typing,it will stop while enter e.“); try while(ch= )!=e) System. ; catch(IOException ioe) System. ; (分数:-1.00)_正确答案:(char)

7、System.in.read() out.print(ch) out.println(ioe.getMessage() )解析:本题主要考查 Java 基本的 I/O 输入输出流,while 循环语句以及对 char 类型数据的操作。解题关键是,熟练掌握 Java 基本的 I/O 操作,会输出异常信息的基本语句。本题中,第 1 个空,判断从屏幕中输入的字符是否为“e“,需将读到的字符转换 char 类型数据,再进行比较;第 2 个空,填入基本的输出语句,完成将 ch 中的数据显示到屏幕中;第 3 个空,会调用返回 I/O 异常信息的方法,并显示到屏幕中。2.简单应用题 请完成下列 Java 程

8、序:运行 3 个线程,每一个线程有自己的标志,用 a,b,c 表示,每个线程显示一个“Start“信息和一个“End“信息并且间隔地显示 2 个“Loop“信息(间隔变化为(0.52)秒之间的随机延迟)。 程序运行结果如下:(注:由于时间间隔为随机数,所以,运行结果的顺序不惟一) a Start b Start c Start b Loop a Loop b Loop b End c Loop a Loop a End c Loop c End 注意:请勿改动 main()主方法和其他已有语句内容,仅在下划线处填入适当的语句。 public class ex2_2 implements Run

9、nable static char flag2_2 = a; public static void main(String arg) ex2_2 obj2_2 = new ex2_2(); Thread thread2_2 = new Thread(obj2_2); thread2_2.start(); thread2_2 = new Thread(obj2_2); thread2_2.start(); thread2_2 = new Thread(obj2_2); thread2_2.start(); public void run() char myflag2_2; synchronize

10、d(this) ; System.out.println(myflag2_2 + “ Start“);for(int i=0; i_正确答案:(myflag2_2 = flag2_2+ (int)(high-low+1)*(Math.random() + low )解析:本题主要考查线程的创建与同步和控制随机数产生范围的算法。解题关键是,熟悉线程的概念和使用,线程的同步控制,char 类型数据的操作,以及熟悉随机数产生的方法 Math.random(),并且能够进一步根据需要控制随机数产生的范围。在本题中,main()方法中创建 3 个线程,这 3 个线程使用 obj2_2 对象。线程调用 s

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

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

展开阅读全文
相关资源
猜你喜欢
  • ASTM E2516-2006 Standard Classification for Cost Estimate Classification System《成本估计分类系统的标准分类》.pdf ASTM E2516-2006 Standard Classification for Cost Estimate Classification System《成本估计分类系统的标准分类》.pdf
  • ASTM E2516-2011 Standard Classification for Cost Estimate Classification System《成本估算分类系统的标准分类》.pdf ASTM E2516-2011 Standard Classification for Cost Estimate Classification System《成本估算分类系统的标准分类》.pdf
  • ASTM E2517-2006 Standard Specification for Cargo Bed Cover Type III (M35A2 2 1 2 Ton Cargo Truck M1078 2 1 2 Ton Lightweight Medium Tactical Vehicle (LMTV) M1082 2 1 2 Ton LMTV Tra.pdf ASTM E2517-2006 Standard Specification for Cargo Bed Cover Type III (M35A2 2 1 2 Ton Cargo Truck M1078 2 1 2 Ton Lightweight Medium Tactical Vehicle (LMTV) M1082 2 1 2 Ton LMTV Tra.pdf
  • ASTM E2517-2011 Standard Specification for Cargo Bed Cover Type III (M35A2 2 1 2 Ton Cargo Truck M1078 2 1 2 Ton Lightweight Medium Tactical Vehicle (LMTV) M1082 2 1 2 Ton LMTV Tra.pdf ASTM E2517-2011 Standard Specification for Cargo Bed Cover Type III (M35A2 2 1 2 Ton Cargo Truck M1078 2 1 2 Ton Lightweight Medium Tactical Vehicle (LMTV) M1082 2 1 2 Ton LMTV Tra.pdf
  • ASTM E2517-2013 Standard Specification for Cargo Bed Cover Type III (M35A2 2 1 2 Ton Cargo Truck M1078 2 1 2 Ton Lightweight Medium Tactical Vehicle (LMTV) M1082 2 1 2 Ton LMTV Tra.pdf ASTM E2517-2013 Standard Specification for Cargo Bed Cover Type III (M35A2 2 1 2 Ton Cargo Truck M1078 2 1 2 Ton Lightweight Medium Tactical Vehicle (LMTV) M1082 2 1 2 Ton LMTV Tra.pdf
  • ASTM E2518-2006 Standard Specification for Cargo Bed Cover Type IV (M923 5 Ton Cargo Truck M1083 5 Ton Medium Tactical Vehicle (MTV) M1082 5 Ton MTV Trailer)《IV型(M923型5吨货运卡车 M1083型.pdf ASTM E2518-2006 Standard Specification for Cargo Bed Cover Type IV (M923 5 Ton Cargo Truck M1083 5 Ton Medium Tactical Vehicle (MTV) M1082 5 Ton MTV Trailer)《IV型(M923型5吨货运卡车 M1083型.pdf
  • ASTM E2518-2011 Standard Specification for Cargo Bed Cover Type IV (M923 5 Ton Cargo Truck M1083 5 Ton Medium Tactical Vehicle (MTV) M1082 5 Ton MTV Trailer)《IV型(M923型5 t货运卡车 M1083.pdf ASTM E2518-2011 Standard Specification for Cargo Bed Cover Type IV (M923 5 Ton Cargo Truck M1083 5 Ton Medium Tactical Vehicle (MTV) M1082 5 Ton MTV Trailer)《IV型(M923型5 t货运卡车 M1083.pdf
  • ASTM E2520-2007 Standard Practice for Verifying Minimum Acceptable Performance of Trace Explosive Detectors《核查痕量爆炸物探测器的最低可接受性能用标准实施规程》.pdf ASTM E2520-2007 Standard Practice for Verifying Minimum Acceptable Performance of Trace Explosive Detectors《核查痕量爆炸物探测器的最低可接受性能用标准实施规程》.pdf
  • ASTM E2520-2015 Standard Practice for Measuring and Scoring Performance of Trace Explosive Chemical Detectors《对微量易爆化学品检测器性能进行测量和评分的标准实践规程》.pdf ASTM E2520-2015 Standard Practice for Measuring and Scoring Performance of Trace Explosive Chemical Detectors《对微量易爆化学品检测器性能进行测量和评分的标准实践规程》.pdf
  • 相关搜索

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

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