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

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

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

2、0.00)_二、2简单应用题(总题数:1,分数:40.00)2.请完成下列 Java 程序:输入 2 个整数,求最大公约数。要求有 2 个单行文本区作为输入,2 个按钮,一个单击完成计算,一个单击退出程序。注意:请勿改动 main()主方法和其他已有语句内容,仅在下划线处填入适当的语句。源程序文件代码清单如下:import java.awt.*;import java.awt.event.*;public class ex7_2 extends Frame implements ActionListenerprivate Label 1;private TextField tf,tf2;pub

3、lic static void main(String args)ex7_2 obj7_2=new ex7_2();public ex7_2()setTitle(“ex7_2“);Panel p1;Button b=new Button(“OK“);p1=new Panel();tf=new TextField(8);p1.add(tf);tf2=new TextField(8);p1.add(tf2);b.addActionListener(this);p1.add(b);b=new Button(“Exit“);b.addActionListener(this);p1.add(b);add

4、North“,p1);Panel p2=new Panel();l=new Label(“最大公因数:“);p2.add(l);add(“Center“,p2);setsize(500,300);show();public void actionPerformed(ActionEvent ae)if(ae.getActionCommand().equals(“Exit“)/比较 ae 对象的标识名,是否为 ExitSystem.exit(0);else if(ae.getActlonCommand().equals(“OK“)tryint a=Integer.parseInt(tf.get

5、Text();int b=Integer.parseInt(tf2.getText();int r,i;while(b0)_;_;b=r;l.setText(“最大公约数: “+Integer.toString(a);catchNumberFormatException nfe)l.setText(“请正确输入!“);(分数:40.00)_三、3综合应用题(总题数:1,分数:30.00)3.下面是一个 Applet 程序,其功能是将完整的图像显示于 Applet 的区块中,然后可以通过拖动鼠标让图像随着鼠标拖动的轨迹而移动。请改正程序中的错误(有下划线的语句),使程序能输出正确的结果。注意:不

6、改动程序的结构,不得增行或删行。源程序文件代码清单如下:import java.applet.*;import java.awt.*;/*applet code=“ex7_3.class“ width=800 height=400/applet*/public class ex7_3 extends Appletprivate Image iImg;private int xPos,yPos;public void init(xPos=yPos=0;iImg=getImage(“ex7_3.jpg“);public void paint(Graphics g)g.drawImage(iImg,

7、xPos,yPos);public boolean mouseDrag(Event e,int x,int y)xPos=x;yPos=y;paint();return true;ex7_3.htmlHTMLHEADTITLEex7_3/TITLE/HEADBODYapplet code=“ex7_3.class“ width=800 height=400/applet/BODY/HTML(分数:30.00)_二级 JAVA 机试-224 答案解析(总分:100.00,做题时间:90 分钟)一、1基本操作题(总题数:1,分数:30.00)1.下面的程序是用 do-while 语句计算 10 的

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

9、掌握main()主方法的使用、while 循环语句的用法。在本题中,string args的作用是声明字符数组args,result*=n-语句的作用是获得 n 的阶乘并赋值给变量 result。二、2简单应用题(总题数:1,分数:40.00)2.请完成下列 Java 程序:输入 2 个整数,求最大公约数。要求有 2 个单行文本区作为输入,2 个按钮,一个单击完成计算,一个单击退出程序。注意:请勿改动 main()主方法和其他已有语句内容,仅在下划线处填入适当的语句。源程序文件代码清单如下:import java.awt.*;import java.awt.event.*;public cla

10、ss ex7_2 extends Frame implements ActionListenerprivate Label 1;private TextField tf,tf2;public static void main(String args)ex7_2 obj7_2=new ex7_2();public ex7_2()setTitle(“ex7_2“);Panel p1;Button b=new Button(“OK“);p1=new Panel();tf=new TextField(8);p1.add(tf);tf2=new TextField(8);p1.add(tf2);b.ad

11、dActionListener(this);p1.add(b);b=new Button(“Exit“);b.addActionListener(this);p1.add(b);add(“North“,p1);Panel p2=new Panel();l=new Label(“最大公因数:“);p2.add(l);add(“Center“,p2);setsize(500,300);show();public void actionPerformed(ActionEvent ae)if(ae.getActionCommand().equals(“Exit“)/比较 ae 对象的标识名,是否为 E

12、xitSystem.exit(0);else if(ae.getActlonCommand().equals(“OK“)tryint a=Integer.parseInt(tf.getText();int b=Integer.parseInt(tf2.getText();int r,i;while(b0)_;_;b=r;l.setText(“最大公约数: “+Integer.toString(a);catchNumberFormatException nfe)l.setText(“请正确输入!“);(分数:40.00)_正确答案:(r=a%ba=b)解析:解析 本题主要考查 AWT 基本构件和

13、事件处理机制以及基本的求最大公因数的算法。解题关键是掌握 Button,Panel,Label 等构件的使用方法,会处理整数异常,熟练掌握 while 语句用法。本题中,第 1 个空,r 为 a 除以 b 的余数;第 2 个空,a 更新为 b 的值。三、3综合应用题(总题数:1,分数:30.00)3.下面是一个 Applet 程序,其功能是将完整的图像显示于 Applet 的区块中,然后可以通过拖动鼠标让图像随着鼠标拖动的轨迹而移动。请改正程序中的错误(有下划线的语句),使程序能输出正确的结果。注意:不改动程序的结构,不得增行或删行。源程序文件代码清单如下:import java.applet

14、import java.awt.*;/*applet code=“ex7_3.class“ width=800 height=400/applet*/public class ex7_3 extends Appletprivate Image iImg;private int xPos,yPos;public void init(xPos=yPos=0;iImg=getImage(“ex7_3.jpg“);public void paint(Graphics g)g.drawImage(iImg,xPos,yPos);public boolean mouseDrag(Event e,in

15、t x,int y)xPos=x;yPos=y;paint();return true;ex7_3.htmlHTMLHEADTITLEex7_3/TITLE/HEADBODYapplet code=“ex7_3.class“ width=800 height=400/applet/BODY/HTML(分数:30.00)_正确答案:(iImg=getImage(getDocumentBase(), “ex7_3.jpg“)g.drawImage(iImg,xPos,yPos,this)repaint()解析:解析 本题主要考查在 Applet 窗口中显示图像,并结合鼠标事件处理的综合应用。解题关键是熟悉图像文件的加载过程,会跟踪鼠标拖动的事件,并将鼠标在 Applet 窗口中的坐标信息作为参数传递给drawImage()方法,用于在新的位置显示图像,从而实现拖动效果。本题中,第 1 处,getImage()方法应该有 2 个参数,第 1 个参数是 getDocumentBase()方法的返回值,即图像文件的路径;第 2 处,drawImage()方法最后 1 个参数应该是 this,确定是在当前运行的。对象中绘制图像;第 3 处,应该调用repaint()方法,进行重画,而不是 paint()方法。程序运行结果如下。

展开阅读全文
相关资源
猜你喜欢
  • ASD-STAN PREN 3864-2001 Aerospace Series Non-Metallic Materials Glass Transparencies Test Methods Determination of Modulus of Rupture (Edition P 1)《航空航天系列 非金属材料 玻璃的透明性 试验方法 断裂模数的测定.pdf ASD-STAN PREN 3864-2001 Aerospace Series Non-Metallic Materials Glass Transparencies Test Methods Determination of Modulus of Rupture (Edition P 1)《航空航天系列 非金属材料 玻璃的透明性 试验方法 断裂模数的测定.pdf
  • ASD-STAN PREN 3866-2001 Aerospace Series Non-Metallic Materials Glass Transparencies Test Methods Determination of Ream and Surface Ripple (Edition P 1)《航空航天系列 非金属材料玻璃的透明性 试验方法 扩孔和.pdf ASD-STAN PREN 3866-2001 Aerospace Series Non-Metallic Materials Glass Transparencies Test Methods Determination of Ream and Surface Ripple (Edition P 1)《航空航天系列 非金属材料玻璃的透明性 试验方法 扩孔和.pdf
  • ASD-STAN PREN 3867-1994 Aerospace Series Pipe Couplings Loose Flanges and Seals Flanges in Titanium Alloy TI-P64001 (Edition P 1)《航空航天系列 钛合金TI-P64001制管接头、松套法兰和密封法兰 第P1版》.pdf ASD-STAN PREN 3867-1994 Aerospace Series Pipe Couplings Loose Flanges and Seals Flanges in Titanium Alloy TI-P64001 (Edition P 1)《航空航天系列 钛合金TI-P64001制管接头、松套法兰和密封法兰 第P1版》.pdf
  • ASD-STAN PREN 3868-1994 Aerospace Series Pipe Couplings Loose Flanges and Seals Flange Connectors Welded in Titanium Alloy TI-P64001 (Edition P 1)《航空航天系列 钛合金TI-P64001制焊接式管接头、松套法兰和密.pdf ASD-STAN PREN 3868-1994 Aerospace Series Pipe Couplings Loose Flanges and Seals Flange Connectors Welded in Titanium Alloy TI-P64001 (Edition P 1)《航空航天系列 钛合金TI-P64001制焊接式管接头、松套法兰和密.pdf
  • ASD-STAN PREN 3869-1994 Aerospace Series Pipe Couplings Loose Flanges and Seals Seals in Fluorocarbon Rubber and Armature in Aluminium Alloy (Edition P 1)《航空航天系列 管接头、松套法兰和氟橡胶制密封垫和铝.pdf ASD-STAN PREN 3869-1994 Aerospace Series Pipe Couplings Loose Flanges and Seals Seals in Fluorocarbon Rubber and Armature in Aluminium Alloy (Edition P 1)《航空航天系列 管接头、松套法兰和氟橡胶制密封垫和铝.pdf
  • ASD-STAN PREN 3870-1993 Aerospace Series Titanium Alloy TI-P19001 Solution Treated and Aged Sheet and Strip Hot Rolled a Less Than or Equal to 6 mm (Edition P 1)《航空航天系列 钛合金TI-P1900.pdf ASD-STAN PREN 3870-1993 Aerospace Series Titanium Alloy TI-P19001 Solution Treated and Aged Sheet and Strip Hot Rolled a Less Than or Equal to 6 mm (Edition P 1)《航空航天系列 钛合金TI-P1900.pdf
  • ASD-STAN PREN 3871-1993 Aerospace Series Titanium Alloy TI-P19001 Solution Treated and Aged Sheet and Strip Cold Rolled a Less Than or Equal to 6 mm (Edition P 1)《航空航天系列 钛合金TI-P190.pdf ASD-STAN PREN 3871-1993 Aerospace Series Titanium Alloy TI-P19001 Solution Treated and Aged Sheet and Strip Cold Rolled a Less Than or Equal to 6 mm (Edition P 1)《航空航天系列 钛合金TI-P190.pdf
  • ASD-STAN PREN 3872-2003 Aerospace Series Aluminium Alloy AL-R39002 H112 Die Forgings a Less Than or Equal to 200 mm (Edition P 2)《航空航天系列 a≤200mm的铝合金AL-R39002 H112模锻件 第P2版》.pdf ASD-STAN PREN 3872-2003 Aerospace Series Aluminium Alloy AL-R39002 H112 Die Forgings a Less Than or Equal to 200 mm (Edition P 2)《航空航天系列 a≤200mm的铝合金AL-R39002 H112模锻件 第P2版》.pdf
  • ASD-STAN PREN 3873-2010 Aerospace series Test methods for metallic materials Determination of fatigue crack growth rates using Corner-Cracked (CC) test pieces (Edition P 1)《航空航天系列 .pdf ASD-STAN PREN 3873-2010 Aerospace series Test methods for metallic materials Determination of fatigue crack growth rates using Corner-Cracked (CC) test pieces (Edition P 1)《航空航天系列 .pdf
  • 相关搜索

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

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