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

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

1、计算机二级(JAVA)上机考试 24 及答案解析(总分:-3.00,做题时间:90 分钟)1.基本操作题 下列程序中,实现将封装数据类型 Integer 和基本数据类型 int 之间的转换,以及Integer, int 类型和 String 类型之间的转换。请将程序补充完整。 程序运行结果如下: 123 456 456 public class ex7_1 public static void main(String args) Integer intObj; int n; String s; intObj=new Integer(123); n=intObj. ; System.out.pr

2、intln(Integer.toString(n); s=new String(“456“); intObj=Integer. ; System.out.println(intObj. ); n=Integer.parseInt(s); System.out.println(Integer.toString(n); (分数:-1.00)_2.简单应用题 请完成下列 Java 程序:创建一个具有 2 行 3 列的 GridLayout 管理器,包括Choice,Label,Button 构件,布局为第 1 行包括一个 Choice 构件(包括 2 个选项 item1 和 item2),一个Lab

3、el 构件(当选择 Choice 构件中的选项时,Label 构件显示相应的名称,即,如果点击 item1 则 Label中显示 item1),和一个 exit 按钮(点击则退出应用程序),第 2 行包括 3 个 Button 构件。程序运行结果如下: (分数:-1.00)_3.综合应用题 下面是一个 Applet 程序,其功能是有 2 个按钮,分别为 First 和 Second,以及一个 Label构件。要求点击 First 时则能在 Label 中显示出 Command:First,而点击 Second 时则能显示出Command:Second,要求只能使用重载一次 actionPerf

4、ormed()方法。请改正程序中的错误(有下划线的语句),使程序能输出正确的结果。程序运行结果如下: (分数:-1.00)_计算机二级(JAVA)上机考试 24 答案解析(总分:-3.00,做题时间:90 分钟)1.基本操作题 下列程序中,实现将封装数据类型 Integer 和基本数据类型 int 之间的转换,以及Integer, int 类型和 String 类型之间的转换。请将程序补充完整。 程序运行结果如下: 123 456 456 public class ex7_1 public static void main(String args) Integer intObj; int n;

5、 String s; intObj=new Integer(123); n=intObj. ; System.out.println(Integer.toString(n); s=new String(“456“); intObj=Integer. ; System.out.println(intObj. ); n=Integer.parseInt(s); System.out.println(Integer.toString(n); (分数:-1.00)_正确答案:(intValue() valueOf(s) toString() )解析:本题主要考查 Java 类库中对简单数据类型的封装以

6、及对封装类型与基本类型之间的转换。解题关键是熟悉基本数据类型的封装,以及一些常用封装类型的常用转换方法,如 Integer 类的 parseInt()方法等。本题中,第 1 个空,使用 intValue()方法将封装对象 intObj 转换为基本的数据类型 int;第 2 个空,使用 valueOf()方法,将字符串转换为封装对象 intObj;第 3 个空,使用 toString()方法,将封装对象 intObj 转换为字符串打印出来,注意,这里不可以加参数。2.简单应用题 请完成下列 Java 程序:创建一个具有 2 行 3 列的 GridLayout 管理器,包括Choice,Label

7、,Button 构件,布局为第 1 行包括一个 Choice 构件(包括 2 个选项 item1 和 item2),一个Label 构件(当选择 Choice 构件中的选项时,Label 构件显示相应的名称,即,如果点击 item1 则 Label中显示 item1),和一个 exit 按钮(点击则退出应用程序),第 2 行包括 3 个 Button 构件。程序运行结果如下: (分数:-1.00)_正确答案:(new GridLayout(2,3) addItemListener(this) )解析:本题主要考查 Java 常用构件 Choice 和高级事件 ItemEvent 以及 Grid

8、Layout 布局管理器的用法。解题关键是,熟悉 GridLayout 布局管理器和 ItemEvent 的用法。在本题中,ItemEvent 在教材中并没有给出确切的用法,但是可以根据 ActionEvent 的 addActionEvent()方法和重载 actionPerformed()方法来完成对动作事件监听的用法来类推出 ItemEvent 事件的监听方法,这里要求有根据已有知识进行举一反三的能力。3.综合应用题 下面是一个 Applet 程序,其功能是有 2 个按钮,分别为 First 和 Second,以及一个 Label构件。要求点击 First 时则能在 Label 中显示出

9、 Command:First,而点击 Second 时则能显示出Command: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 的方法。

展开阅读全文
相关资源
猜你喜欢
  • DIN 38406-1-1983 German standard methods for the examination of water waste water and sludge cations (group E) determination of iron (E 1)《德国检验水、废水和污泥的标准方法 阳离子(E组) 铁的测定(E1)》.pdf DIN 38406-1-1983 German standard methods for the examination of water waste water and sludge cations (group E) determination of iron (E 1)《德国检验水、废水和污泥的标准方法 阳离子(E组) 铁的测定(E1)》.pdf
  • DIN 38406-11-1991 German standard methods for the examination of water waste water and sludge cations (group E) determination of nickel by atomic absorption spectrometry (AAS) (E 1.pdf DIN 38406-11-1991 German standard methods for the examination of water waste water and sludge cations (group E) determination of nickel by atomic absorption spectrometry (AAS) (E 1.pdf
  • DIN 38406-13-1992 German standard methods for the examination of water waste water and sludge cations (group E) determination of potassium by atomic absorption spectrometry (AAS) u.pdf DIN 38406-13-1992 German standard methods for the examination of water waste water and sludge cations (group E) determination of potassium by atomic absorption spectrometry (AAS) u.pdf
  • DIN 38406-14-1992 German standard methods for the examination of water waste water and sludge cations (group E) determination of sodium by atomic absorption spectrometry (ASS) usin.pdf DIN 38406-14-1992 German standard methods for the examination of water waste water and sludge cations (group E) determination of sodium by atomic absorption spectrometry (ASS) usin.pdf
  • DIN 38406-16-1990 German standard methods for the examination of water waste water and sludge cations (group E) determination of zinc cadmium lead copper thallium nickel cobalt by .pdf DIN 38406-16-1990 German standard methods for the examination of water waste water and sludge cations (group E) determination of zinc cadmium lead copper thallium nickel cobalt by .pdf
  • DIN 38406-17-2009 de 2868 German standard methods for the examination of water waste water and sludge - Cations (group E) - Part 17 Determination of uranium - Method using adsorpti.pdf DIN 38406-17-2009 de 2868 German standard methods for the examination of water waste water and sludge - Cations (group E) - Part 17 Determination of uranium - Method using adsorpti.pdf
  • DIN 38406-18-1990 German standard methods for the examination of water waste water and sludge cations (group E) determination of dissolved silver by atomic absorption spectrometry .pdf DIN 38406-18-1990 German standard methods for the examination of water waste water and sludge cations (group E) determination of dissolved silver by atomic absorption spectrometry .pdf
  • DIN 38406-2-1983 German standard methods for the examination of water waste water and sludge cations (group E) determination of manganese (E 2)《德国检验水、废水和污泥的标准方法 阳离子(E组) 锰的测定(E 2)》.pdf DIN 38406-2-1983 German standard methods for the examination of water waste water and sludge cations (group E) determination of manganese (E 2)《德国检验水、废水和污泥的标准方法 阳离子(E组) 锰的测定(E 2)》.pdf
  • DIN 38406-21-1980 German standard methods for the examination of water waste water and sludge cations (group E) determination of nine heavy metals (Ag Bi Cd Co Cu Ni Pb Tl Zn) (E21.pdf DIN 38406-21-1980 German standard methods for the examination of water waste water and sludge cations (group E) determination of nine heavy metals (Ag Bi Cd Co Cu Ni Pb Tl Zn) (E21.pdf
  • 相关搜索

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

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