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

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

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

2、 ) continue; /当 count为 5时跳过循环中的剩余代码 output+=count+“ “: output+=“nUsed continue to skip printing 5“: JOptionPane.showMessageDialog(null,output); System.exit(0); 二、简单应用题( 40分) 2 请 完善程序 (程序文件名: Java_2.java)并进行调试。请在下画线处填入正确内容,然后删除下画线。请勿删除注释行和其他已有的语句内容。 题目要求 打开一个文本文件 test.txt,统计该文件中包含的数字的个数与英文字母的个数(忽略大小写

3、 )。例如 test.txt文本文件中包含的内容为 “123abeDEF99G”,则程序的输出结果如下: 数字数是 5,字母数是 7 源程序: import java.io.*: public class Java_2 public static void main(String args) byte buf=new byte5; int len=0, c1=0, c2=0; (1) FileInputStream in= (2) (“test.txt“); while(len=in.read(bur, 0.5) 0) for(int i=0; i len; i+) if(bufi =0 /返

4、回点的横坐标 public int getY() return y; /返回点的纵坐标 public void move(int x,int y) this.x=x;this.y=y; /把当前点移到新的位置 (x,y)上 public String toString() return“(“+x+“,“+y+“)“; /以 (x,y)的格式返回点的位置 public void translate(int x,int y)this.x+=x;this.y+=y; /在原有坐标上分别增加 x和 y public static void main(String args) Java_3 P= (5)

5、 ; /生成一个对象 (5,5) System.out.println(“x=“+p.x+“y=“+p.y); System.out.println(“Location is“+p.toString(); /12(x,y)的方式打印坐标的位置 (6) ; /在原有位置上增加 (3,4) System.out.println(“x=“+p.x+“y=“+p.y); /打印横坐标和纵坐标的值 System.out.println(“Location is“+p.toString(); /以 (x,y)的方式打印坐标的位置 国家二级( JAVA)机试模拟试卷 101答案与解析 一、基本操作题( 30

6、分) 1 【正确答案】 count+ =5 【试题解析】 当 count为 5时跳过循环,执行下一个循环,所以判断条件为count是否等于 5, Java中用 “=”表示判断是否相等,所以语句为 count=5。 程序解析 本程序主要考查 for循环中的强制跳转语句。强制跳转语句有continue和 break 两种。 break 语句用来退出循环,并从紧跟 该循环语句的第一条语句处开始执行;而 continue语句则跳过循环体中下面尚未执行的语句,回到循环体的开始继续下一轮的循环。 二、简单应用题( 40分) 2 【正确答案】 try new FileInputStream 【试题解析】 由

7、于 in是 FileInputStream类的对象,所以此处需要将 in通过构造方法 FileInputStream(String name)实例化。 FileInputStream(String name)通过打开一个到实际文件的连接来创建一个 FileInputStream,该文件通过文件系统中的路径名 name指定。 程序解析 本程序利用 FileInputStream类从文件中读取一系列字符,然后判断字母和数字个数,将结果输出。 三、综合应用题( 30分) 3 【正确答案】 ( 1) this.x=x;this.y=y; ( 2) this.x=p.x;this.y=p.y; ( 3)

8、 new Java_3(x,y); ( 4) return p ( 5) new Java_3(5,5) ( 6) p.translate(3,4) 【试题解析】 定义构造方法, 由于给了两个参数,所以需要通过参数给类的变量赋值,因此通过 this关键字表明是对当前类的变量赋值。定义构造方法,由于参数给了 Java_3类的对象 p,所以通过这个参数给变量赋值。 注释说明是通过坐标(x,y)进行实例化,所以构造方法需要有两个参数 x和 y。根据注释以及程序中创建的对象 p,需要将 p返回,因此是 return 语句。注释中给出了对象的坐标 (5,5)因此需要通过两个参数 x和 y调用构造方法 Java_3(int x,int y)进行实例化。注释中说明在原有位置增加 (3,4),因此需要对对象调用方法 translate()。可以通过方法的定义看出是在原有位置增加一定值。 程序解析 本程序主要考查类的对象的创建、构造方法的重载和类的方法使用。

展开阅读全文
相关资源
猜你喜欢
  • ASD-STAN PREN 2518-1982 Titanium TI-P02 390 MPa Less Than or Equal to Rm Less Than or Equal to 540 MPa Bars De Less Than or Equal to 200 mm Aerospace Series (Edition 1)《航空航天系列 钛TI-.pdf ASD-STAN PREN 2518-1982 Titanium TI-P02 390 MPa Less Than or Equal to Rm Less Than or Equal to 540 MPa Bars De Less Than or Equal to 200 mm Aerospace Series (Edition 1)《航空航天系列 钛TI-.pdf
  • ASD-STAN PREN 2520-1982 Titanium TI-P04 540 MPa Less Than or Equal to Rm Less Than or Equal to 740 MPa Forgings De Less Than or Equal to 200 mm Aerospace Series (Edition 1)《航空航天系列 .pdf ASD-STAN PREN 2520-1982 Titanium TI-P04 540 MPa Less Than or Equal to Rm Less Than or Equal to 740 MPa Forgings De Less Than or Equal to 200 mm Aerospace Series (Edition 1)《航空航天系列 .pdf
  • ASD-STAN PREN 2522-1982 Titanium Alloy TI-P11 540 MPa Less Than or Equal to Rm - Less Than or Equal to 700 MPa Forgings De Less Than or Equal to 200 mm Aerospace Series (Edition 1).pdf ASD-STAN PREN 2522-1982 Titanium Alloy TI-P11 540 MPa Less Than or Equal to Rm - Less Than or Equal to 700 MPa Forgings De Less Than or Equal to 200 mm Aerospace Series (Edition 1).pdf
  • ASD-STAN PREN 2523-1982 Titanium alloy TI-P11 650 MPa Less Than or Equal to Rm Less Than or Equal to 880 MPa Bars De Less Than or Equal to 75 mm Aerospace Series (Edition 1)《航空航天系列.pdf ASD-STAN PREN 2523-1982 Titanium alloy TI-P11 650 MPa Less Than or Equal to Rm Less Than or Equal to 880 MPa Bars De Less Than or Equal to 75 mm Aerospace Series (Edition 1)《航空航天系列.pdf
  • ASD-STAN PREN 2524-1982 Titanium Alloy TI-P11 650 MPa Less Than or Greater to Rm Less Than or Greater to 880 MPa Forgings De Less Than or Equal to 75 mm Aerospace Series (Edition 1.pdf ASD-STAN PREN 2524-1982 Titanium Alloy TI-P11 650 MPa Less Than or Greater to Rm Less Than or Greater to 880 MPa Forgings De Less Than or Equal to 75 mm Aerospace Series (Edition 1.pdf
  • ASD-STAN PREN 2528-1983 Titanium Alloy TI-P11 540 MPa Less Than Rm Less Than or Equal to 700 MPa Sheets and Strips a Less Than or Equal to 5 mm Aerospace Series (Edition 1)《航空航天系列 .pdf ASD-STAN PREN 2528-1983 Titanium Alloy TI-P11 540 MPa Less Than Rm Less Than or Equal to 700 MPa Sheets and Strips a Less Than or Equal to 5 mm Aerospace Series (Edition 1)《航空航天系列 .pdf
  • ASD-STAN PREN 2531-1983 Titanium Alloy TI-P63 Annealed - 900 MPa Less Than or Equal to Rm Less Than or Equal to 1160 MPa Forgings De Less Than or Equal to 150 mm Aerospace Series (.pdf ASD-STAN PREN 2531-1983 Titanium Alloy TI-P63 Annealed - 900 MPa Less Than or Equal to Rm Less Than or Equal to 1160 MPa Forgings De Less Than or Equal to 150 mm Aerospace Series (.pdf
  • ASD-STAN PREN 2532-1984 Titanium Alloy TI-P68 - 1100 Less Than or Equal to Rm Less Than or Equal to 1280 MPa Bar De Less Than or Equal to 25 mm Aerospace Series (Edition 1)《航空航天系列 .pdf ASD-STAN PREN 2532-1984 Titanium Alloy TI-P68 - 1100 Less Than or Equal to Rm Less Than or Equal to 1280 MPa Bar De Less Than or Equal to 25 mm Aerospace Series (Edition 1)《航空航天系列 .pdf
  • ASD-STAN PREN 2533-1984 Titanium alloy TI-P68 1050 Less Than or Equal to Rm Less Than or Equal to 1220 MPa Bar 25 Less Than De Less Than or Equal to 100 mm Aerospace Series (Editio.pdf ASD-STAN PREN 2533-1984 Titanium alloy TI-P68 1050 Less Than or Equal to Rm Less Than or Equal to 1220 MPa Bar 25 Less Than De Less Than or Equal to 100 mm Aerospace Series (Editio.pdf
  • 相关搜索

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

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