【计算机类职业资格】二级JAVA机试-174及答案解析.doc

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

1、二级 JAVA 机试-174 及答案解析(总分:100.00,做题时间:90 分钟)一、1基本操作题(总题数:1,分数:30.00)请完善程序(程序文件名:Java_1.java)并进行调试。请在下画线处填入正确内容,然后删除下画线。请勿删除注释行和其他已有的语句内容。题目要求请完善程序,并进行调试,程序运行结果为:aa=512bb=-167ff=593.94dd=5.938839067268372源程序:import java.io.*;public class Java_1 public static void main(String args) char a=p:byte b1=6;in

2、t i=400;long b=345L;float f=98.99f;double d=4.7788;(1) aa=a+i;long bb=b-aa;(2) if=b1*f;double dd=ff/aa+d;System.out.println(“aa=“+aa);System.out.println(“bb=“+bb);System.out.println(“ff=“+ff);System.out.println(“dd=“+dd);(分数:30.00)填空项 1:_填空项 1:_二、2简单应用题(总题数:1,分数:40.00)请完善程序(程序文件名:Java_2.java),并进行调试。

3、请在下画线处填入正确内容,然后删除下画线。请勿删除注释行和其他已有的语句内容。题目要求本题功能是创建一个二维整型数组,并将其元素输出。运行结果为:1 1 1 12 2 2 23 3 3 34 4 4 4源程序:public class Java_2 public static void main(String args) int aMatrix=1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4;int i=0;/循环变量int j=0;/循环变量for(i=0;i (1) ;i+) for(j=0;jaMatrixi.length;j+)System.out.print( (2)

4、 +“ “);System.out.println();(分数:40.00)填空项 1:_填空项 1:_三、3综合应用题(总题数:1,分数:30.00)请完善程序(程序文件名:Java_3.java)并进行调试。请在下画线处填入正确内容,然后删除下画线。请勿删除注释行和其他已有的语句内容。题目要求该程序的功能是求以命令行参数指定的整数的阶乘。完成程序并运行,所得结果为:5 的阶乘是 120.0源程序:/程序的功能是求以命令行参数指定的整数的阶乘。public class Java_3 public static void main(String args) String num;if(args

5、length0)Bum= (1) ;else num=“5“:int input=Integer.parseInt( (2) );double result=factorial(input);System.out.println(input+“的阶乘是“+result);public static double factorial(int x) if(x0)return 0.0;double fact=1.0:while(x1) fact (3) * x;x=x-1;return fact;(分数:30.00)填空项 1:_填空项 1:_填空项 1:_二级 JAVA 机试-174 答案解析(

6、总分:100.00,做题时间:90 分钟)一、1基本操作题(总题数:1,分数:30.00)请完善程序(程序文件名:Java_1.java)并进行调试。请在下画线处填入正确内容,然后删除下画线。请勿删除注释行和其他已有的语句内容。题目要求请完善程序,并进行调试,程序运行结果为:aa=512bb=-167ff=593.94dd=5.938839067268372源程序:import java.io.*;public class Java_1 public static void main(String args) char a=p:byte b1=6;int i=400;long b=345L;f

7、loat f=98.99f;double d=4.7788;(1) aa=a+i;long bb=b-aa;(2) if=b1*f;double dd=ff/aa+d;System.out.println(“aa=“+aa);System.out.println(“bb=“+bb);System.out.println(“ff=“+ff);System.out.println(“dd=“+dd);(分数:30.00)填空项 1:_ (正确答案:int)解析:解析 表达式等号右边的变量 a 为 char 型,而 i 为 int 型,所以结果为 int 型,因此等号左边的变量 aa 为 int 型

8、填空项 1:_ (正确答案:float)解析:解析 表达式等号右边的变量 b1 为 byte 型,而 f 为 float 型,所以结果为 float 型,因此等号左边的变量 ff 为 float 型。程序解析 本程序主要考查变量的类型以及不同类型的变量运算后的类型。对二元运算,如果操作数全为整型,那么只要其中有一个为 long 型,则表达式结果也为 long 型;其他情况下,即使两个操作数全是byte 型或 short 型,表达式结果也为 int 型;如果操作数为浮点型,那么只要其中有一个为 double 型,表达式结果就是 double 型;只有两个操作数全是 float 型或其中一个是

9、float 型而另外一个是整型时,表达式结果才是 float 型。二、2简单应用题(总题数:1,分数:40.00)请完善程序(程序文件名:Java_2.java),并进行调试。请在下画线处填入正确内容,然后删除下画线。请勿删除注释行和其他已有的语句内容。题目要求本题功能是创建一个二维整型数组,并将其元素输出。运行结果为:1 1 1 12 2 2 23 3 3 34 4 4 4源程序:public class Java_2 public static void main(String args) int aMatrix=1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4;int i=

10、0;/循环变量int j=0;/循环变量for(i=0;i (1) ;i+) for(j=0;jaMatrixi.length;j+)System.out.print( (2) +“ “);System.out.println();(分数:40.00)填空项 1:_ (正确答案:aMatrix.length)解析:解析 循环变量 i 是控制行的循环,所以为 aMatrix.length。填空项 1:_ (正确答案:aMatrixij)解析:解析 此条语句为输出语句,输出当前元素,因此为 aMatrixij。程序解析 本程序主要考查数组的长度 length,即数组元素的个数。对于二维数组,可视为

11、数组元素,又可视为数组。本程序中的数组即是一个 4 个元素的数组,而每个元素又是一个含有 4 个整型元素的数组。对于本题的二维数组,也可理解为 aMatrix.length 即为行数,aMatrixi.length 即为 i 行的列数。三、3综合应用题(总题数:1,分数:30.00)请完善程序(程序文件名:Java_3.java)并进行调试。请在下画线处填入正确内容,然后删除下画线。请勿删除注释行和其他已有的语句内容。题目要求该程序的功能是求以命令行参数指定的整数的阶乘。完成程序并运行,所得结果为:5 的阶乘是 120.0源程序:/程序的功能是求以命令行参数指定的整数的阶乘。public cl

12、ass Java_3 public static void main(String args) String num;if(args.length0)Bum= (1) ;else num=“5“:int input=Integer.parseInt( (2) );double result=factorial(input);System.out.println(input+“的阶乘是“+result);public static double factorial(int x) if(x0)return 0.0;double fact=1.0:while(x1) fact (3) * x;x=x-1;return fact;(分数:30.00)填空项 1:_ (正确答案:args0)解析:解析 Java 中命令行参数均为字符串类型,且第一个参数为 args0,第二个参数为 args1,以此类推。填空项 1:_ (正确答案:num)解析:解析 由于获取的参数为字符串类型,要经过转换,将其转换为整型。填空项 1:_ (正确答案:=fact)解析:解析 利用循环求阶乘,当 x1 依次相乘累积赋予 fact,所以为 fact=fact*x;,x 递减直到 1为止。程序解析 程序首先从命令行获取参数,然后通过方法调用求阶乘。方法中用了循环以实现求阶乘的算法。

展开阅读全文
相关资源
猜你喜欢
  • BS PAS 92-2011 Code of practice for the implementation of a biometric system《生物识别系统运行操作规范》.pdf BS PAS 92-2011 Code of practice for the implementation of a biometric system《生物识别系统运行操作规范》.pdf
  • BS PAS 96-2010 Defending food and drink Guidance for the deterrence detection and defeat of ideologically motivated and other forms of malicious attack on food and drink and their .pdf BS PAS 96-2010 Defending food and drink Guidance for the deterrence detection and defeat of ideologically motivated and other forms of malicious attack on food and drink and their .pdf
  • BS PD 2379-2005 Register of colours of manufacturers- identification threads for electric cables and cords Tenth Edition《电缆和电线的制造商识别螺纹的颜色登记 第10版》.pdf BS PD 2379-2005 Register of colours of manufacturers- identification threads for electric cables and cords Tenth Edition《电缆和电线的制造商识别螺纹的颜色登记 第10版》.pdf
  • BS PD 25111-2010 PUBLISHED DOCUMENT nBusiness continuity nmanagement – Guidance on nhuman aspects of business ncontinuity《出版文献业务持续性管理 持续性管理的人类方向指南》.pdf BS PD 25111-2010 PUBLISHED DOCUMENT nBusiness continuity nmanagement – Guidance on nhuman aspects of business ncontinuity《出版文献业务持续性管理 持续性管理的人类方向指南》.pdf
  • BS PD 25666-2010 PUBLISHED DOCUMENT nBusiness continuity nmanagement Guidance on nexercising and testing for continuity and contingency nprogrammes《出版文献 业务连续性管理.pdf BS PD 25666-2010 PUBLISHED DOCUMENT nBusiness continuity nmanagement Guidance on nexercising and testing for continuity and contingency nprogrammes《出版文献 业务连续性管理.pdf
  • BS PD 6682-1-2009 Aggregates – Part 1 Aggregates for concrete – Guidance on the use of BS EN 12620《集料 第1部分 混凝土集料 BS EN 12620使用指南》.pdf BS PD 6682-1-2009 Aggregates – Part 1 Aggregates for concrete – Guidance on the use of BS EN 12620《集料 第1部分 混凝土集料 BS EN 12620使用指南》.pdf
  • BS PD 6682-2-2009 Aggregates nPart 2 Aggregates for bituminous mixtures nand surface treatments for roads airfields nand other trafficked areas – Guidance on nthe use of BS EN 1304.pdf BS PD 6682-2-2009 Aggregates nPart 2 Aggregates for bituminous mixtures nand surface treatments for roads airfields nand other trafficked areas – Guidance on nthe use of BS EN 1304.pdf
  • BS PD 6682-6-2009 Aggregates – Part 6 Aggregates for unbound and nhydraulically bound materials for use in civil nengineering works and road construction – Guidance on the use of .pdf BS PD 6682-6-2009 Aggregates – Part 6 Aggregates for unbound and nhydraulically bound materials for use in civil nengineering works and road construction – Guidance on the use of .pdf
  • BS PD 6687-2006 Background paper to the UK National Annexes to BS EN 1992-1《BS EN 1992-1标准的英国国家附录的背景文件》.pdf BS PD 6687-2006 Background paper to the UK National Annexes to BS EN 1992-1《BS EN 1992-1标准的英国国家附录的背景文件》.pdf
  • 相关搜索

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

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