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

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

1、国家二级( JAVA)机试模拟试卷 69及答案与解析 一、基本操作题( 30分) 1 下面程序执行结果为: 11=1 21=2 22=4 31=3 32=6 33=9 91=9 92=18 93=27 94=36 95=45 96=54 97=63 98=72 99=81 请在每条横线处填写一个语句,使程序的功能完整。 注意:请勿改动 main()主方法和其他已有的语句内容,仅在横线处填入适当的语句。 public class ForLoopStatement public static void main(String args) int m,n; for(m=1; m 10; _) _ S

2、ystem.out.print(m+“*“+n+“=“+m*n+“ “); _ 二、简单应用题( 40分) 2 请完成下列 Java程序。程序的功能是利用迭代法求一个数的平方根 (求平方根的迭代公式为: Xn+1=1/2(Xn+a/Xn) 注意:请勿改动 main()主方法和其他已有的语句内容,仅在下划线处填入适当的语句。 public class PingFangGen public static void main(String args) System. out. println(Math, sqrt(2.0); static double sqrt(_) double x=1.0 do

3、 _ while( Math. abs(x*x-a)/a le-6) return x; 三、综合应用题( 30分) 3 下面是一个 Applet程序,其功能是接收用户输入的两个整数,比较它们的大小,并在用户按下 “比较大小 ”按钮后,将 Applet中显示的 “请先输入两个待比较的整数 ”,改为 “两个整数中最大值是: x”, x是两个数中的最大值。请改正程序中的错误 (有下划线的语句 ),使程序 能输出正确的结果。 注意:不改动程序的结构,不得增行或删行。 import java. applet. *; import java. awt. * import java. awt. event

4、 *; /* applet code= LookForMax width= 800 height= 400 /applet */ public class LookForMax extends Applet implements ActionListener Label result; TextField in1,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

5、 = new Button(“比较大小 “); add(in1); add(in2) add(btn) add(result) btn. addActionListener(super) public void actionPerformed(ActionEvent e) a=Integer. parseInt(in1); b=Integer. parselnt(in2); if (a b) max=a; else max=b; result . setText(“两个数中最大值是 : “+max); LookFormax. html; html head title A Simple Pro

6、gram /title /head body applet code=“LookForMax, class“ width 800 height=400 /applet /body /html 国家二级( JAVA)机试模拟试卷 69答案与解析 一、基本操作题( 30分) 1 【正确答案】 m+ for(n=1; n =m; n+) System out println(); 【试题解析】 本题考查 Java的循环语句。本题中 m+;语句是使循环变量的值递增 1,第一个 for (m=1; m 10; m+)循环语句是用来控制乘法表的行输出,那么还要用一个 for循环语句来实现控制列的输出。这个

7、列的变量 n要注意,它总是小于等于 m的,所以应有 for(n=1; n =m; n+);语句System out println();是用来换行输出。 二、简单应用题( 40分) 2 【正确答案】 double a x=(x+a/x); 【试题解析】 本题主要考查 do-while循环语句及 Java的基本运算。 do-while循环又称 “直到型 ”循环,它的一般格式为: 初始化部分 do循环体部分;迭代部分; while(判断部分 );。说明如下: (1)do-while结构首先执行循环体,然后计算终止条件,若结果为 true,则循环执行大括号中的语句或代码块,直到布尔表达式的结果为 f

8、alse。 (2)与 while结构不同的是, do-while结构的循环至少被执行一次,这是 “直到型 ”循环的特点。在本题中, double a语句是定义一个 double型变量 a, x=(x+a/x);语句的功能是迭代求出被开平方的变量。 三、综合应用题( 30分) 3 【正确答案】 this in1 getText() in2 getText() 【试题解析】 本题主要考查 Java Applet程序的编写、 java awt包的基本 组件的使用及 super和 this关键字的使用。 Applet(小程序 )是一种很重要的 Java程序,是工作在 Internet的浏览器上或借助

9、JDK中的 appletviewer来工作的 Java程序。编写 Applet小程序必须要用到 java applet包中的 Applet类。java applet Applet是 java awt Panel的子类。 在本题中, public class LookForMax extends Applet implements ActionListener语句的功能是声明一个继承 Applet类且实现 ActionListener接口的类 LookForMax来实现程序功能, btn addActionListener(this);语句的功能是为按钮 btn对象注册一个事件监听器 this(this是指当前 LookForMax的对象 ), a=Integer parseInt (in 1 getText();和 b=Integer parseInt(in 2 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