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

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

1、国家二级( JAVA)机试模拟试卷 40及答案与解析 一、基本操作题( 30分) 1 下面程序执行后,输出结果为: true请在程序的每条横线处填写一个语句,使程序的功能完整。 注意:请勿改动 main()主方法和其他已有的语句内容,仅在横线处填入适当的语句。 public class TestStringCompare public static void main(String _ args) char charl=t,e,s,t; char char2=t,e,s,t,1; String str1=new String(_); String str2=new String(char2,0

2、4); System.out.println(_); 二、简单应用题( 40分) 2 请完成下列 Java程序。程序的功能是显示用户在命令行方式下指定的任意驱动器目录的内容。 (提示: public Stringlist(); /将目录中所有文件名保存在字符数组中返回 ) 注意:请勿改动 main()主方法和其他已有的语句内容,仅在下划线处填入适当的语句。 import java.io.*; public class FindDirectories public static void main(String args if(args.length=0) args=new String“;

3、try _ String fileName=pathName.list(); for(int i=0;ifileName.length;i+ File f=new File(pathName.getPath() fileNamei); if(_) System.out.println(f.getCanonicalPath(); main(new String f.getPath() ); catch(IOException e) e.printStackTrace(); 三、综合应用题( 30分) 3 下面是一个 Applet程序,其功能是接收用户输入的两个整数,比较它们的大小,并在用户按下

4、比较大小 ”按钮后,将 Applet中显示的 “请先输入两个待比较的整数 ”,改为 “两个整数中最大值是: x”, x是两个数中的最大值。请改正程序中的错误 (有下划线的语句 ),使程序能输出正确的结果。 注意:不改动程序的结构,不得增行或删行。 程序运行结果如下: import java.applet.*; import java.awt.*; import java.awt.event.*; /* applet code=LookForMax width=800 height=400 /applet */ public class LookForMax extends Applet im

5、plements ActionListener Label result ; TextField inl,in2; Button btn; int a=0,b=0,max=0; public void init() result=new Label (“请先输入两个待比较得整数 “); in1=new TextField(5); in2=new TextField(5); btn=new Button(“比较大小 “); add(in1); add(in2); add(btn); add(result); btn.addActionListener(supper); public void a

6、ctionPerformed(ActionEvent e) a=Integer.parseInt(in1); b=Integer.parseInt(in2); if(a b) max=a; else max=b; result, setText ( “两个数中最大值是: “+max); LookFormax.html: html head title A Simple Program /title /head body applet code=“LookForMax.class“ width=800 height=400 /applet /body /html 国家二级( JAVA)机试模拟试

7、卷 40答案与解析 一、基本操作题( 30分) 1 【正确答案】 char1 str1 equals(str2) 【试题解析】 本题主要考查 main()主方法的使用、 String类的使用。解答本题的关键是熟练掌握 main()主方法的使用、 String类的使用。在本题中, public static void main(Stringargs)中的 是定义数组的标志, str1 equals(str2)语句的功能是判断字符串 str1和字符串 str2的内容是否相等。 二、简单应用题( 40分) 2 【正确答案】 File pathName=new File(args0); f isDir

8、ectory() 【试题解析】 本题主要考查对文件操作的基本知识。解答本题的关键是熟练掌握对文件操作的基本知识。其中, File pathName=new File(args0);语句的功能是生成 File类对象 pathName; if(f.isDirectory()语句的功能是判断生成的 f对象是否为目录。 三、综合应用题( 30分) 3 【正确答案】 this in1 getText() in2 getText() 【试题解析】 本题主要考查 JavaApplet程序的编写、 java awt包的基本组件的使用及 supper和 this关键字的使用。解答本题的关键是熟练掌握 Java

9、Applet程序的编写、 java awt包的基本组件的使用及 supper和 this关键字的使用。Applet(小程序 )是一种很重要的 Java程序,是工作在 Internet的浏览器上或借助JDK中的 appletviewer来工作的 Java程序。编写 Applet小程序必须要用到java appelt包中的 Applet类。 java applet Applet是 java awt Panel的子类。 在本题中, public class LookForMax extends Appkt implements ActionListener语句的功能是声明一个继承 Applet类且实现 ActionListener接口的类LookForMax来实现程序功能, btn.addActionListener(this);语句的功能是为按钮btn对象注册一个事件监听器 this(this是指当前 LookForMax的对象 )a=Integer.parseInt(in1 getText();和 a=Integer.parseInt(in1.getText();语句的功能是把从文本框 in1和 in2获得的字符型数据转换成基本整型数据,并把这两个值分别赋给变量 a和 b。

展开阅读全文
相关资源
猜你喜欢
  • BS PD IEC TS 62763-2013_5284 Pilot function through a control pilot circuit using PWM (pulse width modulation) and a control pilot wire《通过控制导向线使用PWM (脉冲宽度调制) 的导向功能和控制导向线》.pdf BS PD IEC TS 62763-2013_5284 Pilot function through a control pilot circuit using PWM (pulse width modulation) and a control pilot wire《通过控制导向线使用PWM (脉冲宽度调制) 的导向功能和控制导向线》.pdf
  • BS ISO 8070-2007 Milk and milk products - Determination of calcium sodium potassium and magnesium contents - Atomic absorption spectrometric method《牛奶和奶制品 钙、钠、钾和镁含量的测定 原子吸.pdf BS ISO 8070-2007 Milk and milk products - Determination of calcium sodium potassium and magnesium contents - Atomic absorption spectrometric method《牛奶和奶制品 钙、钠、钾和镁含量的测定 原子吸.pdf
  • BS ISO 8082-1-2009 Self-propelled machinery for forestry - Laboratory tests and performance requirements for roll-over protective structures - General machines《林业用自推进机械 防倾.pdf BS ISO 8082-1-2009 Self-propelled machinery for forestry - Laboratory tests and performance requirements for roll-over protective structures - General machines《林业用自推进机械 防倾.pdf
  • BS ISO 8082-2-2011 Self-propelled machinery for forestry Laboratory tests and performance requirements for roll-over protective structures Machines having a rotating platf.pdf BS ISO 8082-2-2011 Self-propelled machinery for forestry Laboratory tests and performance requirements for roll-over protective structures Machines having a rotating platf.pdf
  • BS ISO 8083-2006 Machinery for forestry - Falling-object protective structures (FOPS) - Laboratory tests and performance requirements《林业机械 落体防护装置(FOPS) 实验室试验和性能要求》.pdf BS ISO 8083-2006 Machinery for forestry - Falling-object protective structures (FOPS) - Laboratory tests and performance requirements《林业机械 落体防护装置(FOPS) 实验室试验和性能要求》.pdf
  • BS ISO 8086-2004 Dairy plant - Hygiene conditions - General guidance on inspection and sampling procedures《乳品厂 卫生条件 检验和取样程序通用指南》.pdf BS ISO 8086-2004 Dairy plant - Hygiene conditions - General guidance on inspection and sampling procedures《乳品厂 卫生条件 检验和取样程序通用指南》.pdf
  • BS ISO 8096-2005 Rubber- or plastics-coated fabrics for water resistant clothing - Specification《雨衣用橡胶或塑料涂覆织物 规范》.pdf BS ISO 8096-2005 Rubber- or plastics-coated fabrics for water resistant clothing - Specification《雨衣用橡胶或塑料涂覆织物 规范》.pdf
  • BS ISO 8097-2001 Aircraft Minimum airworthiness requirements and test conditions for certified air cargo unit load devices《航空器 经认证的航空货运集装单元装置最低适航性要求和试验条件》.pdf BS ISO 8097-2001 Aircraft Minimum airworthiness requirements and test conditions for certified air cargo unit load devices《航空器 经认证的航空货运集装单元装置最低适航性要求和试验条件》.pdf
  • BS ISO 8114-1993 Textile machinery and accessories - Spindles for ring-spinning and doubling machines - List of equivalent terms《纺织机械和附件 环锭纺纱机和并线机用锭子 同义术语表》.pdf BS ISO 8114-1993 Textile machinery and accessories - Spindles for ring-spinning and doubling machines - List of equivalent terms《纺织机械和附件 环锭纺纱机和并线机用锭子 同义术语表》.pdf
  • 相关搜索

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

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