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

上传人:jobexamine331 文档编号:503529 上传时间:2018-11-29 格式:DOC 页数:3 大小:70KB
下载 相关 举报
[计算机类试卷]国家二级(JAVA)机试模拟试卷103及答案与解析.doc_第1页
第1页 / 共3页
[计算机类试卷]国家二级(JAVA)机试模拟试卷103及答案与解析.doc_第2页
第2页 / 共3页
[计算机类试卷]国家二级(JAVA)机试模拟试卷103及答案与解析.doc_第3页
第3页 / 共3页
亲,该文档总共3页,全部预览完了,如果喜欢就下载吧!
资源描述

1、国家二级( JAVA)机试模拟试卷 103及答案与解析 一、基本操作题( 30分) 1 请完善程序 (程序文件名: Java_1.java)并进行调试。请在下画线处填入正确内容,然后删除下画线。请勿删除注释行和其他已有的语句内容。 题目要求 完成程序并运行,得到的结果如下图所示。 源程序: import javax.swing.JOptionPane; public class Java_1 int x=0; String s= (1) ; public static void main(String args) Java_1 d=new (2) ; String output; output

2、=“After instantiation:n“+“x:“+d.x+“s:“+d.s; d.x=77; d.s=“Good bye“; output+=“nAfter changing values:n“+“x:“+d.x+“s“+d.s: JOptionPane.showMessageDialog(null,output,“Demonstrating Package Access“, JOptionPane.INFORMATION_MESSAGE); System.exit(0); 二、简单应用题( 40分) 2 请完善程序 (程序文件名: Java_2.java)并进行调试。请在下画线处填

3、入正确内容,然后删除下画线。请勿删除注释行和其他已有的语句内容。 题目要求 程序显示一个窗口。该窗口包含一个按钮和一个文本域,当单击按钮时将在文本域中显示当前日期,如下图所示。源程序: import java.awt.*; import java.awt.event.*; import java.util.*; public class Java_2 implements ActionListener Frame f; Button b; TextField tf; public (1) () f=new Frame(“Show Date“); f.setLayout(new FlowLayo

4、ut(); f.setSize(400,100); /注册窗口监听器 (Window Listener) (2) (new WindowAdapter() public void windowClosing(WindowEvent e) System.exit(0); ); b=new Button(“显示当前日期 “); b.addActionListener(this); tf=new TextField(30); f.add(b); f.add(tf); f.setVisible(true); public static void main(String args) Java_2 t=n

5、ew Java_2(); public void actionPerformed(ActionEvent e) Date d=new Date(); /获取当前日期 tf.setText(d.toString(); 三、综合应用题( 30分) 3 请完善程序 (程序文件名: Java_3.java)并进行调试。请在下画线处填入正确内容,然后删除下画线。请勿删除注释行和其他已有的语句内容。 题目要求 统计一个英文文本字符串包含的英文元音 字母的个数,使程序的运行结果如下: The text contained vowels:88 源程序: public class Java_3 public s

6、tatic void main(String args) String text = “ Beijing, the Capital City, is the political, “ + “cultural and diplomatic centre of China. It has“ + “become a modern international cosmopolitan city“ + “ with more than 11 million people. The Capital“ + “ International Airport, 23.5 km from the city cent

7、re,“ + “is Chinas largest and most advanced airport. “ ; int vowels =0; int (1) = text.length(); for(int i = 0;i textLength; i+) char ch=Character.toLowerCase( text. (2) ); if(ch=a|ch=e|ch=i|ch=o|ch=u) (3) ; System.out.println( “The text contained vowels:“ + vowels +“n“); 国家二级( JAVA)机试模拟试卷 103答案与解析

8、一、基本操作题( 30分) 1 【正确答案】 ( 1) “Hello“ ( 2) Java_1() 【试题解析】 根据题目输出结果可以看出,实例化后未给重新赋值时,变量 s的内容是字符串 “Hello“,所以对变量 S 的初始化值即 “Hello“。程序中定义 d 为Java_1类的对象,所以对类实例化,即通过默认的构造方法创建对象。 程序解析 本程序通过类实例化获取类对象,改变对象的变量 ,将其通过对话框输出。 二、简单应用题( 40分) 2 【正确答案】 Java_2 f.addWindowListener 【试题解析】 程序的注释中已经给出注册窗口监听器,而且由下面的方法windowCl

9、osing 可以看出是窗口监听器,所以是给 Frame类实例 f 注册窗口监听器。 程序解析 本程序通过按钮在文本域显示当前系统时间。程序中用到了构造方法,因为在 main()方法中只是创建了对象,进行了实例化。另外也涉及事件监听接口。 三、综合应用题( 30分) 3 【正确答案】 textLength charAt(i) vowels+ 【试题解析】 由最后的输出语句判断出变量 vowels 表述元音的个数,因此统计出一个元音变量 vowels就加 1,所以此处应填 vowels+。 程序解析 本程序统计一个字符串中元音字母的个数,然后输出。由于统计时是不区分大小写的,所以在比较前,先将字符串的每个字母都小写,再进行比较。

展开阅读全文
相关资源
猜你喜欢
  • ASTM A986 A986M-2001(2011) Standard Specification for Magnetic Particle Examination of Continuous Grain Flow Crankshaft Forgings《连续晶粒流向曲轴锻件的磁粉探伤检查标准规范》.pdf ASTM A986 A986M-2001(2011) Standard Specification for Magnetic Particle Examination of Continuous Grain Flow Crankshaft Forgings《连续晶粒流向曲轴锻件的磁粉探伤检查标准规范》.pdf
  • ASTM A986 A986M-2001(2016) Standard Specification for Magnetic Particle Examination of Continuous Grain Flow Crankshaft Forgings《连续晶粒流动曲轴锻件的磁粉探伤检验的标准规格》.pdf ASTM A986 A986M-2001(2016) Standard Specification for Magnetic Particle Examination of Continuous Grain Flow Crankshaft Forgings《连续晶粒流动曲轴锻件的磁粉探伤检验的标准规格》.pdf
  • ASTM A987 A987M-2009 Standard Practice for Measuring Shape Characteristics of Tin Mill Products《锡轧制品的形状特性测量用标准规范》.pdf ASTM A987 A987M-2009 Standard Practice for Measuring Shape Characteristics of Tin Mill Products《锡轧制品的形状特性测量用标准规范》.pdf
  • ASTM A987 A987M-2009(2014) Standard Practice for Measuring Shape Characteristics of Tin Mill Products《镀锡薄钢板轧制产品形状特性测量的标准试验方法》.pdf ASTM A987 A987M-2009(2014) Standard Practice for Measuring Shape Characteristics of Tin Mill Products《镀锡薄钢板轧制产品形状特性测量的标准试验方法》.pdf
  • ASTM A987-2005 Standard Test Method for Measuring Shape Characteristics of Tin Mill Products《测量锡轧制品形状特性的标准试验方法》.pdf ASTM A987-2005 Standard Test Method for Measuring Shape Characteristics of Tin Mill Products《测量锡轧制品形状特性的标准试验方法》.pdf
  • ASTM A987-2007 Standard Practice for Measuring Shape Characteristics of Tin Mill Products《锡轧制产品的形状特性测量的标准实施规程》.pdf ASTM A987-2007 Standard Practice for Measuring Shape Characteristics of Tin Mill Products《锡轧制产品的形状特性测量的标准实施规程》.pdf
  • ASTM A988 A988M-2007 Standard Specification for Hot Isostatically-Pressed Stainless Steel Flanges Fittings Valves and Parts for High Temperature Service《高温下使用的热等静加压成形的不锈钢法兰盘、管配件、阀及.pdf ASTM A988 A988M-2007 Standard Specification for Hot Isostatically-Pressed Stainless Steel Flanges Fittings Valves and Parts for High Temperature Service《高温下使用的热等静加压成形的不锈钢法兰盘、管配件、阀及.pdf
  • ASTM A988 A988M-2011 Standard Specification for Hot Isostatically-Pressed Stainless Steel Flanges Fittings Valves and Parts for High Temperature Service《高温下使用的热等静加压成形的不锈钢法兰盘 管配件 阀及.pdf ASTM A988 A988M-2011 Standard Specification for Hot Isostatically-Pressed Stainless Steel Flanges Fittings Valves and Parts for High Temperature Service《高温下使用的热等静加压成形的不锈钢法兰盘 管配件 阀及.pdf
  • ASTM A988 A988M-2013 Standard Specification for Hot Isostatically-Pressed Stainless Steel Flanges Fittings Valves and Parts for High Temperature Service《高温设备用热等静压不锈钢法兰盘、管配件、阀及零件的标准.pdf ASTM A988 A988M-2013 Standard Specification for Hot Isostatically-Pressed Stainless Steel Flanges Fittings Valves and Parts for High Temperature Service《高温设备用热等静压不锈钢法兰盘、管配件、阀及零件的标准.pdf
  • 相关搜索

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

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