【计算机类职业资格】二级JAVA机试-148及答案解析.doc
《【计算机类职业资格】二级JAVA机试-148及答案解析.doc》由会员分享,可在线阅读,更多相关《【计算机类职业资格】二级JAVA机试-148及答案解析.doc(7页珍藏版)》请在麦多课文档分享上搜索。
1、二级 JAVA 机试-148 及答案解析(总分:100.00,做题时间:90 分钟)一、1基本操作题(总题数:1,分数:30.00)1.下面程序是关于类的继承的用法。阅读下面程序,根据程序中的注释在每一条横线处填写一个语句,使程序的功能完整,且运行程序后的输出结果为:I am parentclass!I am childclass!I am childclass!注意:请勿改动 main()主方法和其他已有的语句内容,仅在下划线处填入适当的语句。class Parent void printMe() System. out. println( “I am parentclass ! “);cl
2、ass Child extends Parent void printMe() System. out. println( “I am childclass! “)void printAll() _. printMe(); /调用父类的方法_. printMe(); /调用本类的方法printMe ( );public class TestJieCheng public static void main(String args) _myC. printAll();(分数:30.00)_二、2简单应用题(总题数:1,分数:40.00)2.请完成下列 Java 程序。程序的功能是利用迭代法求一个数
3、的平方根(求平方根的迭代公式为:Xn+1=1/2(Xn+a/Xn)注意:请勿改动 main()主方法和其他已有的语句内容,仅在下划线处填入适当的语句。public class PingFangGenpublic static void main(String args)System. out. println(Math, sqrt(2.0);static double sqrt(_)double x=1.0do_while( Math. abs(x*x-a)/ale-6)return x;(分数:40.00)_三、3综合应用题(总题数:1,分数:30.00)3.下面是一个 Applet 程序,
4、其功能是输入 3 个双精度浮点数:a,b,c,构成一个一元二次方程,a*x*x+b*x+c=0,其判别式 d=b*b-4*a*c,若 d 为负数则输出“没有实根”,否则打印出 2 个实根。要求,有 3 个输入框,输入 a,b,c,一个按钮,点击实现求根过程,一个不可编辑的文本区,用作输出结果。请改正程序中的错误(有下划线的语句),使程序能输出正确的结果。注意:不改动程序的结构,不得增行或删行。import java. io. *import java. awt. *import java. awt. event. *import java. applet. Applet;/*applet co
5、de=“ex3_1. class“ width=800 height=400/applet*/public class ex3_1 extends Applet implements ActionListenerPanel pane= new Panel();Label 11=new Label(“a: “)TextField tf1 =new TextField(5)Label 12 = new Label (“b: “)TextField tf2=new TextField(5);Label 13=new Label(“c:“)TextField tf3=new TextField(5);
6、Button btn= new Button(“OK“)Label 14=new Label(“答案“)TextField tf4=new TextField(20);ex3_1 obj3_1public void init()pane. setLayout( new FlowLayout (FlowLayout. LEFT, 10,5 ) )pane. add(11)pane. add(tf1)pane. add(12)pane. add(tf2)add( “North“, pane)Panel p2=new Panel();p2. setLayout ( new FlowLayout (
7、FlowLayout. LEFT, 10, 5) )p2. add(13);p2. add(tf3)p2. add(btn)btn. addActionListener(this);add(“Center“,p2)Panel p3=new Panel ()p3. setLayout ( new FlowLayout (FlowLayout. LEFT, 10,5 ) )p3. add(14)tf4. setEditable(false)p3. add(tf4)add(“South“ ,p3)obj3_1 = new ex3_1 ( )public void doReal(double a1,d
8、ouble a2,double a3,TextField tf)double d, x1, x2d=a1 * a1-4.0 * a2 * a3;if(d=0.0)x1=(-a2+Math. sqrt(d)/(2.0 * a1);x2=(-a2+Math. sqrt(d)/(2.0 * a1);tr. setText(“2 个实根:x1=“+x1+“/nx2=“+x2);else tr. setText ( “没有实根!“)public void actionPerformed(ActionEvent ae)double a, b, c;trya= new Double(tf1. getText
9、( ) ). doubleValue( );b= new Double(tf2. getText( ) ). doubleValue( );c= new Double(tf3. getText( ) ). doubleValue( );obj3_1, doReal(a,b,c, 14);catch(NumberFormatException nfe) tf4. setText( “wrong number!“)ex3_l. htmlHTMLHEADTITLE ex3_l /TITLE/HEADBODYapplet code=“ex3_l, class“ width=800 height=400
10、/applet/BODY/HTML(分数:30.00)_二级 JAVA 机试-148 答案解析(总分:100.00,做题时间:90 分钟)一、1基本操作题(总题数:1,分数:30.00)1.下面程序是关于类的继承的用法。阅读下面程序,根据程序中的注释在每一条横线处填写一个语句,使程序的功能完整,且运行程序后的输出结果为:I am parentclass!I am childclass!I am childclass!注意:请勿改动 main()主方法和其他已有的语句内容,仅在下划线处填入适当的语句。class Parent void printMe() System. out. println
- 1.请仔细阅读文档,确保文档完整性,对于不预览、不比对内容而直接下载带来的问题本站不予受理。
- 2.下载的文档,不会出现我们的网址水印。
- 3、该文档所得收入(下载+内容+预览)归上传者、原创作者;如果您是本文档原作者,请点此认领!既往收益都归您。
下载文档到电脑,查找使用更方便
5000 积分 0人已下载
下载 | 加入VIP,交流精品资源 |
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 计算机 职业资格 二级 JAVA 机试 148 答案 解析 DOC
