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

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

1、二级 JAVA机试 44及答案解析(总分:100.00,做题时间:90 分钟)一、B1基本操作题/B(总题数:1,分数:30.00)1.下面的程序是用 do_while语句计算 10的阶乘。请在程序的每条横线处填写一个语句,使程序的功能完整。 注意:请勿改动 main()主方法和其他已有的语句内容,仅在横线处填入适当的语句。 源程序文件代码清单如下: public class DoWhileLoop public static void main(_) int n=10; long result=1; do _ _ System.out.println(“10的阶乘为: “+result);

2、分数:30.00)_二、B2简单应用题/B(总题数:1,分数:40.00)2.以下程序中,当用户单击“移动”按钮以后,就可以使用方向键控制屏幕上句子的移动,单击“停止”按钮,则句子不再随着方向键移动。运行结果如下图所示 (分数:40.00)_三、B3综合应用题/B(总题数:1,分数:30.00)3.下面是一个 Applet程序,其功能是将完整的图像显示于 Applet的区块中,然后可以通过拖动鼠标让图像随着鼠标拖动的轨迹而移动。请改正程序中的错误(有下划线的语句),使程序能输出正确的结果。注意:不改动程序的结构,不得增行或删行。 源程序文件代码清单如下: import java.applet

3、 import java.awt.*; /* applet code=“ex7_3.class“ width=800 height=400 /applet */ public class ex7_3 extends Applet private Image iImg; private int xPos,yPos; public void init() xPos = yPos = 0; UiImg = getImage(“ex7_3.jpg“)/U; public void paint(Graphics g) Ug.drawImage(iImg,xPos,yPos)/U; public b

4、oolean mouseDrag(Event e,int x, int y) xPos = x; yPos = y; Upaint()/U; return true; ex7_3.html HTML HEAD TITLEex7_3/TITLE /HEAD BODY applet code=“ex7_3.class“ width=800 height=400 /applet /BODY /HTML(分数:30.00)_二级 JAVA机试 44答案解析(总分:100.00,做题时间:90 分钟)一、B1基本操作题/B(总题数:1,分数:30.00)1.下面的程序是用 do_while语句计算 10

5、的阶乘。请在程序的每条横线处填写一个语句,使程序的功能完整。 注意:请勿改动 main()主方法和其他已有的语句内容,仅在横线处填入适当的语句。 源程序文件代码清单如下: public class DoWhileLoop public static void main(_) int n=10; long result=1; do _ _ System.out.println(“10的阶乘为: “+result); (分数:30.00)_正确答案:()解析:String args result*=n-; while(n=1); 解析 本题主要考查 main()主方法的使用、while循环语句的用

6、法。解答本题的关键是熟练掌握 main()土方法的使用、while 循环语句的用法。在本题中,String args的作用是声明字符数组 args, result*=n-;语句的作用是获得 n的阶乘并赋值给变量 result。二、B2简单应用题/B(总题数:1,分数:40.00)2.以下程序中,当用户单击“移动”按钮以后,就可以使用方向键控制屏幕上句子的移动,单击“停止”按钮,则句子不再随着方向键移动。运行结果如下图所示 (分数:40.00)_正确答案:()解析:init addKeyListener 解析 本题考查知识点:小应用程序概念、Applet 执行过程、JavaApplication

7、和 Applet。解题思路:Applet 运行时,首先由浏览器调用 init方法,该方法通知Applet已被加载,在这个方法中通常进行一些基本的初始化过程。Applet 的基本方法还有 start()、stop()、destroy()。类 Example2_8实现了“KeyListener”监听器接口,就可以通过该监听器的方法监听键盘事件。需要填空的方法是初始化 Applet程序,keyPressed()方法中专门处理方向键的事件。按下方向键以后,就会调用 Label的 setLocation()方法重新设置“out”所在的位置。当用户按下“移动”按钮以后,AddMoveListener 为“

8、移动按钮”添加了针对键盘的监听器。当用户按下“停止移动”按钮以后,RemoveListener 从“移动”按钮中移出针对键盘事件的监听器。 本题中 start方法已经实现,另外两个方法分别用于 Applet的停止和卸载,所以第一个空只能填“init”,用来为 Applet实现初始化。 由于本题是使用键盘来控制 Label对象的移动,所以必须添加针对键盘的监听器,这样才能对键盘事件做出反应,第二个空就是给“button”添加键盘事件监听器。三、B3综合应用题/B(总题数:1,分数:30.00)3.下面是一个 Applet程序,其功能是将完整的图像显示于 Applet的区块中,然后可以通过拖动鼠标

9、让图像随着鼠标拖动的轨迹而移动。请改正程序中的错误(有下划线的语句),使程序能输出正确的结果。注意:不改动程序的结构,不得增行或删行。 源程序文件代码清单如下: import java.applet.*; import java.awt.*; /* applet code=“ex7_3.class“ width=800 height=400 /applet */ public class ex7_3 extends Applet private Image iImg; private int xPos,yPos; public void init() xPos = yPos = 0; UiIm

10、g = getImage(“ex7_3.jpg“)/U; public void paint(Graphics g) Ug.drawImage(iImg,xPos,yPos)/U; public boolean mouseDrag(Event e,int x, int y) xPos = x; yPos = y; Upaint()/U; return true; ex7_3.html HTML HEAD TITLEex7_3/TITLE /HEAD BODY applet code=“ex7_3.class“ width=800 height=400 /applet /BODY /HTML(分

11、数:30.00)_正确答案:()解析:iImggetImage(getDocumentBase(),“ex7_3.jpg“) gdrawImaSe(iImg,xPOs,yPOs,this) repaint() 解析 本题主要考查在 Applet窗口中显示图像,并结合鼠标事件处理的综合应用。解题关键是熟悉图像文件的加载过程;会跟踪鼠标拖动的事件,并将鼠标在 Applet窗口中的坐标信息作为参数传递给 drawImage()方法,用于在新的位置显示图像,从而实现拖动效果。本题中,第一处,getImaSe()方法应该有 2个参数,第一个参数是 SetDocumentBase()方法的返回值,即图像文件的路径;第二处,drawImage()方法最后一个参数应该是 this,确定是在当前运行的对象中绘制图像;第三处,应该调用repaint()方法,进行重画,而不是 paint()方法。程序运行结果如下:

展开阅读全文
相关资源
猜你喜欢
  • EN 16145-2012 en Sanitary tapware - Extractable outlets for sink and basin mixers - General technical specification《卫生tapware 可抽出的渠道下沉盆地搅拌机 通用技术规范》.pdf EN 16145-2012 en Sanitary tapware - Extractable outlets for sink and basin mixers - General technical specification《卫生tapware 可抽出的渠道下沉盆地搅拌机 通用技术规范》.pdf
  • EN 16146-2012 en Sanitary tapware - Extractable shower hoses for sanitary tapware for supply systems type 1 and type 2 - General technical specification (Incorporates Amendment A1 .pdf EN 16146-2012 en Sanitary tapware - Extractable shower hoses for sanitary tapware for supply systems type 1 and type 2 - General technical specification (Incorporates Amendment A1 .pdf
  • EN 16147-2017 en Heat pumps with electrically driven compressors - Testing performance rating and requirements for marking of domestic hot water units (Incorporates Corrigendum 201.pdf EN 16147-2017 en Heat pumps with electrically driven compressors - Testing performance rating and requirements for marking of domestic hot water units (Incorporates Corrigendum 201.pdf
  • EN 16150-2012 en Water quality - Guidance on pro-rata Multi-Habitat sampling of benthic macro-invertebrates from wadeable rivers《水质 可涉水过的河流中水底大型无脊椎动物专用-放免法测(抗)甲状腺抗体多栖息地取样导则》.pdf EN 16150-2012 en Water quality - Guidance on pro-rata Multi-Habitat sampling of benthic macro-invertebrates from wadeable rivers《水质 可涉水过的河流中水底大型无脊椎动物专用-放免法测(抗)甲状腺抗体多栖息地取样导则》.pdf
  • EN 16153-2013 en Light transmitting flat multiwall polycarbonate (PC) sheets for internal and external use in roofs walls and ceilings - Requirements and test methods (Incorporates.pdf EN 16153-2013 en Light transmitting flat multiwall polycarbonate (PC) sheets for internal and external use in roofs walls and ceilings - Requirements and test methods (Incorporates.pdf
  • EN 16155-2012 en Foodstuffs - Determination of sucralose - High performance liquid chromatographic method《食品 三氯蔗糖测定 高效液相色谱法》.pdf EN 16155-2012 en Foodstuffs - Determination of sucralose - High performance liquid chromatographic method《食品 三氯蔗糖测定 高效液相色谱法》.pdf
  • EN 16156-2010 en Cigarettes - Assessment of the ignition propensity - Safety requirement《卷烟 易着火性评定 安全性要求》.pdf EN 16156-2010 en Cigarettes - Assessment of the ignition propensity - Safety requirement《卷烟 易着火性评定 安全性要求》.pdf
  • EN 16158-2012 en Animal feeding stuffs - Determination of semduramicin content - Liquid chromatographic method using a  tree  analytical approach《动物饲料 霉素含量的测定 应用树状分析方法的液相层析法》.pdf EN 16158-2012 en Animal feeding stuffs - Determination of semduramicin content - Liquid chromatographic method using a tree analytical approach《动物饲料 霉素含量的测定 应用树状分析方法的液相层析法》.pdf
  • EN 16159-2012 en Animal feeding stuffs - Determination of selenium by hydride generation atomic absorption spectrometry (HGAAS) after microwave digestion (digestion with 65 % nitri.pdf EN 16159-2012 en Animal feeding stuffs - Determination of selenium by hydride generation atomic absorption spectrometry (HGAAS) after microwave digestion (digestion with 65 % nitri.pdf
  • 相关搜索

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

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