[计算机类试卷]国家二级(JAVA)机试模拟试卷62及答案与解析.doc

上传人:sumcourage256 文档编号:503597 上传时间:2018-11-29 格式:DOC 页数:6 大小:40KB
下载 相关 举报
[计算机类试卷]国家二级(JAVA)机试模拟试卷62及答案与解析.doc_第1页
第1页 / 共6页
[计算机类试卷]国家二级(JAVA)机试模拟试卷62及答案与解析.doc_第2页
第2页 / 共6页
[计算机类试卷]国家二级(JAVA)机试模拟试卷62及答案与解析.doc_第3页
第3页 / 共6页
[计算机类试卷]国家二级(JAVA)机试模拟试卷62及答案与解析.doc_第4页
第4页 / 共6页
[计算机类试卷]国家二级(JAVA)机试模拟试卷62及答案与解析.doc_第5页
第5页 / 共6页
点击查看更多>>
资源描述

1、国家二级( JAVA)机试模拟试卷 62及答案与解析 一、基本操作题( 30分) 1 下列程序中,要求按照从大到小的顺序输出 0 100之间 (包括 0和 100)的能被 3整除的所有偶数,并输出符合上述要求的数的个数,请将程序补充完整。程序运行结果如下。 96,90,84,78,72,66,60,54,48,42,36,30,24,18,12,6,0, 源程序文件代码清单如下: public class ex12_1 private int cnt=0; public static void main(String args) ex12_1 obj12_1=new ex12_1(); obj

2、12_1.method12_1(); public void method12_1() for (_) if(_ System.out.print (i+ “, “); _; System.out.println(); System.out.println(cnt); 二、简单应用题( 40分) 2 请完成下列 Java程序;实现 JComboBox,包含 3个选项,分别是 java、 c+、vb,以及 1个文本区,用于显示选择结果。 注意:请勿改动 main()主方法和其他已有语句内容,仅在下划线处填入适当的语句。 源程序文件代码清单如下: import java.awt.event.*;

3、import javax.swing.*; import java.awt.*; public class ex14_2 extends JFrame implements ItemListener BorderLayout bLay = new BorderLayout(); JTextField jtf = new JTextField(27); JComboBox jcb = new JComboBox(); public ex14_2() super (“ex14_2“);/调用当前类 ex14_2的父类 JFrame的构造方法。 jcb.addItemListener(this);

4、jcb.addItem(“java“); jcb.addItem(“c+“); jcb.addItem(“vb“); jcb.setEditable(false); jtf.setHorizontalAlignment(SwingConstants.CENTER); jtf.setEditable(false); JPanel jp = new JPanel(); jp.setLayout(bLay); jp.add(jtf, “South“); jp.add(jcb, “Center“); setContentPane(jp); public static void main(String

5、args) JFrame frame = new ex14_2(); frame.pack(); frame.setVisible(true); public void itemStateChahged(ItemEvent ie) Object o = if (o = job) Object newO; _; jtf.setText(newO.toString()+“被选中 !“); repaint(); 三、综合应用题( 30分) 3 下面是一个 Applet程序,其功能是建立一个图形用户界面的窗口,包括一个文本显示区和一个按钮,单击按钮,可以在文本区已有的文本基础上追加显示 10条“欢迎您

6、,参加 Java考试 !”信息,并且文本区由滚动条控制文 本的上下滚动。请改正程序中的错误 (有下划线的语句 ),使程序能输出正确的结果。 注意:不改动程序的结构,不得增行或删行。 源程序文件代码清单如下; import javax.swing.*; import java.awt.*; import java.awt.event.*; applet code=“ex13_3.class“ width=800 height=400 /applet public class ex13_3 extends JApplet JButton jb = new JButton(“Add Text“);

7、JTextPane jtp = new JTextPane(); public void init() jb.addActionListener(new ActionListener() public void actionPerformed(ActionEvent e) for(int i=1; i 10; i+) jtp.getText(jtp.setText()+ “欢迎您,参加 Java考试 !“); ); Container cp = getContentPane(); cp.add(new JScrollPane(jtp); cp.add(BorderLayout. SOUTH,

8、jtp); public static void main(String args) ex13_3 obj13_3=new ex13_3(); String str = obj13_3.getClass().toString(); if(str.indexOf(“class“) !=-1) str=str.substring(6); JFrame frm = new JFrame(str); frm.addWindowListener(new WindowAdapter() public void windowClosing(WindowEvent we) System.exit(0); );

9、 frm.getContentPane ().addiex13 3); frm.setSize(300, 400); frm.setVisible(true); ex13_3.html HTML HEAD TITLE ex13_3 /TITLE /HEAD BODY applet code=“ex13_3.class“ width=800 height=400 /applet /BODY /HTML 国家二级( JAVA)机试模拟试卷 62答案与解析 一、基本操作题( 30分) 1 【正确答案】 int i=100; i =0; i- i%6=0或者 i%2=0&i%3=0 cnt+ 【试题解

10、析】 本题主要考查 for循环语句和 if条件判断语句以及 +、 %操作符的使用。解题关键是:要读懂题目要求,注意是倒序排列和同时被 2和 3整除的数,并且应该包括 0在内;会使用计数器进行计数。本题中,第 1个空,注意循环变量 i的边界值应该从 100开始一直到 0为止做递减;第 2个空,注意 i需要同时满足被 2和 3整除;第 3个空,计数器做累加 ,统计符合要求的数的个数。 二、简单应用题( 40分) 2 【正确答案】 ie.getSource() newO=ie.getItem() 【试题解析】 本题主要考查用 swing进行图形用户界面开发。解题关键是熟悉JTextField和 JC

11、omboBox等构件的使用方法,以及事件处理机制,掌握在 swing环境下的 ItemListener监听器的使用方法。本题中,第 1个空, ItemEvent类的 ie对象调用 getSource()方法获得发生事件的对象 o:第 2个空, ie调用 getItem()方法获 得选项的对象,并写给新的对象 newO。 三、综合应用题( 30分) 3 【正确答案】 jtp.setText(jtp.qetText()+“欢迎您,参加 Java考试 !n”) cp.add(BorderLayout.SOUTH.jb) frm.getContentPane().add(obj13_3) 【试题解析】

12、 本题主要考查 Applet和 Swing结合进行图形用户界面设计的综合应用。解题关键是掌握 Swing的基本构件 JTextPanel,JButton, JScrollPanel的用法,掌握 BorderLayout布局管理器的使用方法,以及熟练掌握最基本的对象概念。本题中,第 1处, JTextPanel的两个基本方法, setText()和 getText(),熟悉这两个功能,则很容易就能将错误改正;第 2处,应该是通过 BorderLayout布局管理器在窗口的最下方添加一个 JButton对象,需要清楚程序中每个对象所对应的类;第 3处,应该是将类 ex13_3的对象。 obj13_3加入容器中,而不是把类作为参数传递给 add()方法。程序的输出结果如下。

展开阅读全文
相关资源
猜你喜欢
  • BS PD CEN TR 10317-2014 European certified reference materials (EURONORM-CRMs) for the determination of the chemical composition of iron and steel products prepared under .pdf BS PD CEN TR 10317-2014 European certified reference materials (EURONORM-CRMs) for the determination of the chemical composition of iron and steel products prepared under .pdf
  • BS PD CEN TR 10350-2009 0000 Analysis of steels nand irons — Internal nlaboratory procedure nfor checking the naccuracy of an nanalytical method nby using Certified nReference Mat.pdf BS PD CEN TR 10350-2009 0000 Analysis of steels nand irons — Internal nlaboratory procedure nfor checking the naccuracy of an nanalytical method nby using Certified nReference Mat.pdf
  • BS PD CEN TR 10362-2014 Chemical analysis of ferrous materials Determination of selenium in steels Electrothermal atomic absorption spectrometric method《钢铁材料的化学分析 钢中硒的测定 电.pdf BS PD CEN TR 10362-2014 Chemical analysis of ferrous materials Determination of selenium in steels Electrothermal atomic absorption spectrometric method《钢铁材料的化学分析 钢中硒的测定 电.pdf
  • BS PD CEN TR 10364-2016 Steels and cast irons Determination of lead cadmium mercury hexavalent chromium polybrominated biphenyls (PBB) and polybrominated diphenylethers (P.pdf BS PD CEN TR 10364-2016 Steels and cast irons Determination of lead cadmium mercury hexavalent chromium polybrominated biphenyls (PBB) and polybrominated diphenylethers (P.pdf
  • BS PD CEN TR 12098-6-2016 Controls for heating systems Accompanying TR prEN 12098-1 2015 Modules M3-5 6 7 8《供暖系统用控制 引用TR prEN 12098-1-2015 M3-5 6 7 8模块》.pdf BS PD CEN TR 12098-6-2016 Controls for heating systems Accompanying TR prEN 12098-1 2015 Modules M3-5 6 7 8《供暖系统用控制 引用TR prEN 12098-1-2015 M3-5 6 7 8模块》.pdf
  • BS PD CEN TR 12098-7-2016 Controls for heating systems Accompanying TR prEN 12098-3 2015 Modules M3-5 6 7 8《供暖系统用控制 引用TR prEN 12098-3-2015 M3-5 6 7 8模块》.pdf BS PD CEN TR 12098-7-2016 Controls for heating systems Accompanying TR prEN 12098-3 2015 Modules M3-5 6 7 8《供暖系统用控制 引用TR prEN 12098-3-2015 M3-5 6 7 8模块》.pdf
  • BS PD CEN TR 12401-2009 Dentistry — Guidance non the classification nof dental devices and naccessories《牙科 牙科用装置和附件的分类指南》.pdf BS PD CEN TR 12401-2009 Dentistry — Guidance non the classification nof dental devices and naccessories《牙科 牙科用装置和附件的分类指南》.pdf
  • BS PD CEN TR 12831-2-2017 Energy performance of buildings Method for calculation of the design heat load Explanation and justification of EN 12831-1 Module M3-3《建筑的能源性能 设计.pdf BS PD CEN TR 12831-2-2017 Energy performance of buildings Method for calculation of the design heat load Explanation and justification of EN 12831-1 Module M3-3《建筑的能源性能 设计.pdf
  • BS PD CEN TR 12831-4-2017 Energy performance of buildings Method for calculation of the design heat load Explanation and justification of EN 12831-3 Module M8-2 M8-3《建筑物能源.pdf BS PD CEN TR 12831-4-2017 Energy performance of buildings Method for calculation of the design heat load Explanation and justification of EN 12831-3 Module M8-2 M8-3《建筑物能源.pdf
  • 相关搜索

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

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