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

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

1、二级 JAVA 机试 84 及答案解析(总分:100.00,做题时间:90 分钟)一、B1基本操作题/B(总题数:1,分数:30.00)1.下列程序中,定义了一个 3 行 4 列的数组 A,并将 A 的内容转换为 ASCII 码值,并复制到数组 B 中,然后打印出来。 注意:请勿改动 main()主方法和其他已有语句内容,仅在横线处填入适当语句。 public class Example1_4 private char A = a, b, c, d, e, f, g, h, i, j, k, l; public int _; /生成一个空的 3 行 4 列的数组 B public void c

2、opy() for(int i = 0; i 3; i+) for(int j = 0; j 4; j+) _; public static void main(_ argv) Example1_4 example = new Example1_4(); example.copy(); for(int i = 0; i 3; i +) for(int j = 0; j 4; j+) System.out.print(example. Bi j *+“ “); System.out.println (); (分数:30.00)_二、B2简单应用题/B(总题数:1,分数:40.00)2.下列程序用

3、来显示用户要求打开的图片。在名为“读取图像”的 JFrame 框架中有一个单行文本框,用户可以在其中输入图片文件的文件名称,按下“浏览图片”按钮以后,新生成一个对话框,将图片显示在这个对话框中,运行结果如下图所示。请填写横线处的内容。 (分数:40.00)_三、B3综合应用题/B(总题数:1,分数:30.00)3.下面程序是一个计时器,从 1000 秒开始倒计时,直到为 0 结束。在界面上有两个按钮,一个可以暂停计时,另一个可以继续已经暂停的计时。请更正题中带下划线的部分。 注意:不改动程序的结构,不得增行或删行 import java.awt.*; import java.awt.event

4、 import java.applet.Applet; public class Example3_4 extends Applet public Color color = Color.red; private int num= 1000; public Counter theCounter; private Button stop; private Button start; public void init() stop = new Button(“暂停“); start = new Button (“继续“); theCounter = new Counter(this); Us

5、top.addActionListener(new Lst() implements ActionListener/U public void actionPerformed(ActionEvent e) theCounter.sus(); ); start.addActionListener(new SuspenListener(); add(start); add(stop); theCounter.start(); public void paint(Graphics g) g.setCotor(color); g.drawString(String.valueOf(num),50,50

6、); public void setInt(int i) num=i; class SuspenListener implements ActionListener public void actionPerformed(ActionEvent e) theCounter.conti (); Upublic class Counter extends Thread/U Example3_4 example; boolean isHold; Counter (Example3_4 ex) this.example = ex; isHold = false; public void sus() i

7、sHold = true; public synchronized void conti() isHold = false; notify(); public void run() for (int i = 1000; i0; i-) if (i%2 = 1) example.color = Color.red; else example.color = Color.blue; example.setInt(i); example.repaint(); try sleep(1000); Usynchronized/U while(isHold) wait ( ); catch (Interru

8、ptedException ie) HTML HEAD TITLEExample3_4/TITLE /HEAD BODY applet code=“Example3_4.class“ width=300 height=400 /applet /BODY /HTML(分数:30.00)_二级 JAVA 机试 84 答案解析(总分:100.00,做题时间:90 分钟)一、B1基本操作题/B(总题数:1,分数:30.00)1.下列程序中,定义了一个 3 行 4 列的数组 A,并将 A 的内容转换为 ASCII 码值,并复制到数组 B 中,然后打印出来。 注意:请勿改动 main()主方法和其他已有语

9、句内容,仅在横线处填入适当语句。 public class Example1_4 private char A = a, b, c, d, e, f, g, h, i, j, k, l; public int _; /生成一个空的 3 行 4 列的数组 B public void copy() for(int i = 0; i 3; i+) for(int j = 0; j 4; j+) _; public static void main(_ argv) Example1_4 example = new Example1_4(); example.copy(); for(int i = 0;

10、 i 3; i +) for(int j = 0; j 4; j+) System.out.print(example. Bi j *+“ “); System.out.println (); (分数:30.00)_正确答案:()解析:B=new int34 Bij=Aij String 解析 本题主要考查考生对数组的掌握情况,以及数据类型之间的转换。 Java 语言中,数组必须使用“new”关键字对其分配存储空间,因此第一个空需要填写“new int34”。 main 函数的参数列表必须是字符串数组,但是作为参数,是动态获取的,所以没有数组长度,而仅仅写成 Stringargv,由此得到了第

11、 3 个空。第 2 空是考查数据自动转换。 Java 的基本数据类型可以按照一定的规则自动转换,而不需要特殊处理。故第 2 个空可以直接用等号赋值。二、B2简单应用题/B(总题数:1,分数:40.00)2.下列程序用来显示用户要求打开的图片。在名为“读取图像”的 JFrame 框架中有一个单行文本框,用户可以在其中输入图片文件的文件名称,按下“浏览图片”按钮以后,新生成一个对话框,将图片显示在这个对话框中,运行结果如下图所示。请填写横线处的内容。 (分数:40.00)_正确答案:()解析:new ImageIcon(fileName) setIcon 解析 本题是将图片作为图标显示到构件中。

12、ImageDialog 是程序自定义的一个对话框类,在其中添加了一个 JLabel 对象“imageLabel”, setImage方法可以将名为“icon”的图片添加到 imageLabel 中,显示到界面上,ImageDialog 对话框的标题为图片文件的文件名。 actionPerformed 方法相应“浏览图片”按钮对应的事件。按下按钮以后,首先获得用户输入的文件名,以及对应的图片,然后生成 ImageDialog 的对象,调用其中的 setImage 方法把图片显示出来。 第 1 个空是获得根据文件名获得图片。直接根据文件名新建一个 ImageIcon 对象。 第 2 个空考查构件添

13、加图标的方法。JLabel 添加图标的方法是 setIcon()。三、B3综合应用题/B(总题数:1,分数:30.00)3.下面程序是一个计时器,从 1000 秒开始倒计时,直到为 0 结束。在界面上有两个按钮,一个可以暂停计时,另一个可以继续已经暂停的计时。请更正题中带下划线的部分。 注意:不改动程序的结构,不得增行或删行 import java.awt.*; import java.awt.event.*; import java.applet.Applet; public class Example3_4 extends Applet public Color color = Color

14、red; private int num= 1000; public Counter theCounter; private Button stop; private Button start; public void init() stop = new Button(“暂停“); start = new Button (“继续“); theCounter = new Counter(this); Ustop.addActionListener(new Lst() implements ActionListener/U public void actionPerformed(ActionEv

15、ent e) theCounter.sus(); ); start.addActionListener(new SuspenListener(); add(start); add(stop); theCounter.start(); public void paint(Graphics g) g.setCotor(color); g.drawString(String.valueOf(num),50,50); public void setInt(int i) num=i; class SuspenListener implements ActionListener public void a

16、ctionPerformed(ActionEvent e) theCounter.conti (); Upublic class Counter extends Thread/U Example3_4 example; boolean isHold; Counter (Example3_4 ex) this.example = ex; isHold = false; public void sus() isHold = true; public synchronized void conti() isHold = false; notify(); public void run() for (

17、int i = 1000; i0; i-) if (i%2 = 1) example.color = Color.red; else example.color = Color.blue; example.setInt(i); example.repaint(); try sleep(1000); Usynchronized/U while(isHold) wait ( ); catch (InterruptedException ie) HTML HEAD TITLEExample3_4/TITLE /HEAD BODY applet code=“Example3_4.class“ widt

18、h=300 height=400 /applet /BODY /HTML(分数:30.00)_正确答案:()解析:stop.addActionListener(new ActionListener() class Counter extends Thread synchronized(this) 解析 本程序使用线程类“Counter”来实现计时的功能,该线程的线程体每1000 毫秒循环一次,并在每次循环的开始显示剩余的时间。计时器的暂停和继续通过线程的同步与共享来完成,每次循环结束时,判断标志暂停的变量“isHold”是否为真,如果为真则进入挂起状态。当用户按下“暂停”按钮,程序调用 Cou

19、nter 类的 sus()方法,将变量“isHold”设为真。当用户按下“继续”按钮,程序调用 Counter 类的 conti()方法,将变量“isHold”设为假,并使用 notify()取消线程的挂起状态。 本题第 1 个错误是考查对匿名类的使用。匿名类是 Java 语言中比较特殊的一种类,这种类不存在类名,而且只能在声明的时候被实例化一次。匿名类必须继承于一个父类或实现一个接口。第 1 条横线处,原程序打算声明一个新类 Lst 实现 ActionListener 接口,并同时实例化一个新对象。但是只有匿名类才能在声明时创建一个新的类对象。因此此处应改用匿名类实现程序的目的。 第 2 个

20、错误处考查 Java 源程序的结构。任何一个“java”文件中有且只有一个被声明为 public 的类,这个类的名字必须与“java”文件的文件名相同。因此在第 2 个错误位置处必须去掉 public 声明。 synchronized 用来定义一个同步块。 synchronized 的定义格式是 synchronized (expression)statement,expression 是对象或类的名字,系统将为该对象设置唯一的锁;statement 可以是一个方法定义,也可以是一个语句块,在同一时刻只能有一个线程执行这个块中的操作。因此第 3 个错误处必须指明同步的对象,本题中的同步对象是当前的 Counter 实例。 运行结果如下图所示。

展开阅读全文
相关资源
猜你喜欢
  • EN 3297-1998 en Aerospace Series - Inserts Thin Wall Self-Locking MJ Threads in Heat Resisting Nickel Base Alloy NI-P100HT (Inconel 718) - Technical Specification《航空和航天系列 薄壁 自锁 耐高温.pdf EN 3297-1998 en Aerospace Series - Inserts Thin Wall Self-Locking MJ Threads in Heat Resisting Nickel Base Alloy NI-P100HT (Inconel 718) - Technical Specification《航空和航天系列 薄壁 自锁 耐高温.pdf
  • EN 3298-2008 en Aerospace series - Inserts thin wall self-locking - Installation and removal procedure《航空航天系列 薄壁自锁紧插件装配和拆卸程序》.pdf EN 3298-2008 en Aerospace series - Inserts thin wall self-locking - Installation and removal procedure《航空航天系列 薄壁自锁紧插件装配和拆卸程序》.pdf
  • EN 3299-2007 en Aerospace series - Shaft-nuts and threaded rings self-locking right- or left-hand MJ threads in heat resisting steel FE-PA2601 (A286) silver plated - Technical spec.pdf EN 3299-2007 en Aerospace series - Shaft-nuts and threaded rings self-locking right- or left-hand MJ threads in heat resisting steel FE-PA2601 (A286) silver plated - Technical spec.pdf
  • EN 33-2011 en WC pans and WC suites - Connecting dimensions (Incorporating corrigendum June 2013)《WC锅和WC套件 连接尺寸(取代 CEN EN 34CEN EN 37 CEN EN 38)》.pdf EN 33-2011 en WC pans and WC suites - Connecting dimensions (Incorporating corrigendum June 2013)《WC锅和WC套件 连接尺寸(取代 CEN EN 34CEN EN 37 CEN EN 38)》.pdf
  • EN 330-2014 en Wood preservatives - Determination of the relative protective effectiveness of a wood preservative for use under a coating and exposed out-of-ground contact - Field .pdf EN 330-2014 en Wood preservatives - Determination of the relative protective effectiveness of a wood preservative for use under a coating and exposed out-of-ground contact - Field .pdf
  • EN 3301-2007 en Aerospace series - Bolts T-head close tolerance medium thread length in heat resisting steel FE-PM1708 (FV535) uncoated - Classification 1 000 MPa 550 《航空航天系列 非涂覆FE.pdf EN 3301-2007 en Aerospace series - Bolts T-head close tolerance medium thread length in heat resisting steel FE-PM1708 (FV535) uncoated - Classification 1 000 MPa 550 《航空航天系列 非涂覆FE.pdf
  • EN 3302-2007 en Aerospace series - Bolts in heat resisting steel FE-PM1708 (FV535) - Classification 1 000 MPa 550 C - Technical specification《航空航天系列 FE-PM1708(FV535)型钢耐热钢制螺栓 等级-100.pdf EN 3302-2007 en Aerospace series - Bolts in heat resisting steel FE-PM1708 (FV535) - Classification 1 000 MPa 550 C - Technical specification《航空航天系列 FE-PM1708(FV535)型钢耐热钢制螺栓 等级-100.pdf
  • EN 3302-2017 en Aerospace series - Bolts in heat resisting steel FE-PM1708 (FV535) - Classification 1 000 MPa 550 - Technical specification.pdf EN 3302-2017 en Aerospace series - Bolts in heat resisting steel FE-PM1708 (FV535) - Classification 1 000 MPa 550 - Technical specification.pdf
  • EN 3304-1996 en Aerospace Series - Screws 100 Degree Countersunk Reduced Head Offset Cruciform Recess Close Tolerance Normal Shank Short Thread in Titanium Alloy Anodized MoS2 Lubr.pdf EN 3304-1996 en Aerospace Series - Screws 100 Degree Countersunk Reduced Head Offset Cruciform Recess Close Tolerance Normal Shank Short Thread in Titanium Alloy Anodized MoS2 Lubr.pdf
  • 相关搜索

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

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