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

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

1、二级 JAVA 机试 65 及答案解析(总分:100.00,做题时间:90 分钟)一、B1基本操作题/B(总题数:1,分数:30.00)1.在程序中,给出两个整数 4 和 5,计算他们的和,并在屏幕上显示出来。请将程序补充完整。 注意:请勿修改 main()主方法和其他已有语句内容,仅在横线处填入适当语句。 _Add private int a; private int b; public Add(int n1,int n2) a=nl; b=n2; public int getAdd() return a +b; public class basic public _void main(St

2、ring args) int n1=4, n2=5; Add aAddB=_Add(nl,n2); System.out.println(“4+5=“+aAddB.getAdd(); (分数:30.00)_二、B2简单应用题/B(总题数:1,分数:40.00)2.请完成 Java 程序:本题是一个冒泡排序程序的实例。冒泡排序的含义是将相邻的两个数作比较,如果是升序排列的话,如果前边的数大,则将两个数交换。从第一个数开始两两比较一次,就可以将最大的数移动到最后。 注意:请勿修改 main()主方法和其他已有语句内容,仅在横线处填入适当语句。 import java.io.*; public cl

3、ass simple public static intData=new int10; public static void main(String args) int i; int Index; Index=0; InputStreamReader ir; BufferedReader in; ir=new InputStreamReader(System.in); in=new BufferedReader(ir); try do System.out.println(“Please input the number“+ Index+“you want to sort(Exit for 0

4、):“); String s=in.readLine(); DataIndex=Integer.parseInt(s); Index+; while(DataIndex-1!=0); catch(IOException e) System.out.println(e.getMessage(); System.out.print(“Before bubble sorting:“); for(i=0; iIndex-1; i+) System.out.print(“ “+Datai+“ “); System.out.println(“ “); BubbleSort(Index-1); System

5、out.print(“After Bubble Sorting:“); for(i=0; iIndex-1;i+) System.out.print(“ “+Datai+“ “); System.out.println(“ “); public static void BubbleSort(int Index) int i, j, k; boolean Change; int Temp; for(j=Index; j1;j-) Change=false; for(i=0; ij-1;i+) if(Datai+1Datai) Temp=Datai+1; Datai+1=Datai; _; _;

6、 if(Change) System.out.print(“Current Sorting Result:“); for(k=0; kIndex; k+) System.out.print(“ “+Datak+“ “); System.out.println(“ “); (分数:40.00)_三、B3综合应用题/B(总题数:1,分数:30.00)3.下面是一个 Applet 程序,其功能是从 3100 之间(包括 3 和 100)每隔 0.5 秒显示一个新的数字,如果数字为素数,则显示为灰色,其他为绿色。请更正题中带下划线的部分。 注意:不改变程序的结构,不得增行或删行。 import jav

7、a.awt.*; import java.applet.Applet; /* applet code=“exl5_3.class“width=800 height=400 /applet */ public class ex15_3 extends Applet public Color color15_3=Color.black; private int n15_3=3; public myPrime thPrimel5_3; public void init() thPrimel5_3=new myPrime(this); thPrimel5_3.start(); public void

8、paint(Graphics g) g.setColor(Colorl5_3); Ug.drawString(n15_3,50,50)/U; public int getInt() return n15_3; class myPrime extends Thread ex15_3 objl5_3; myPrime(ex15_3 o) this.objl5_3=o; public boolean isPrime(int n) boolean bPrime=true; int i=2; if(n3|n100) return false; while(in-1 i+; return bPrime;

9、public void run() int i; for(i=3;Ui100/U;i+) if(isPrime(i) objl5_3.color15_3=Color.gray; else objl5_3.color15_3=Color.green; Uobj15_3.n15_3;/U objl5_3.repaint(); try sleep(500); catch(InterruptedException ie) exl5_3.html HTML HEAD TITLEexl5_3/TITLE /HEAD BODY applet code=“exl5_3.class“ width=800 hei

10、ght=400 /applet /BODY /HTML(分数:30.00)_二级 JAVA 机试 65 答案解析(总分:100.00,做题时间:90 分钟)一、B1基本操作题/B(总题数:1,分数:30.00)1.在程序中,给出两个整数 4 和 5,计算他们的和,并在屏幕上显示出来。请将程序补充完整。 注意:请勿修改 main()主方法和其他已有语句内容,仅在横线处填入适当语句。 _Add private int a; private int b; public Add(int n1,int n2) a=nl; b=n2; public int getAdd() return a +b; pu

11、blic class basic public _void main(String args) int n1=4, n2=5; Add aAddB=_Add(nl,n2); System.out.println(“4+5=“+aAddB.getAdd(); (分数:30.00)_正确答案:()解析:class new static 讲解 本题考查知识点:面向对象编程的基本概念和特征,类的基本组成和使用,对象的生成和使用。解题思路:本题主要考查 Java 编程中类的使用。主方法生成 Add 类对象的实例aAddB,然后调用 getAdd()方法计算出 4 加 5 的和。首先,定义类必须使用关键字

12、 class,因此第 1 个空应该填写 class。在生成类的对象时,必须使用关键字 new,由此得到第 2 个空。 Main 方法作为 Java 的一个特殊方法,其最大的特点就是这个方法始终都是静态的,因为一个程序必须要有一个静态的入口,系统才能对其进行调用,所以第 3 个空应该填写 static。二、B2简单应用题/B(总题数:1,分数:40.00)2.请完成 Java 程序:本题是一个冒泡排序程序的实例。冒泡排序的含义是将相邻的两个数作比较,如果是升序排列的话,如果前边的数大,则将两个数交换。从第一个数开始两两比较一次,就可以将最大的数移动到最后。 注意:请勿修改 main()主方法和其

13、他已有语句内容,仅在横线处填入适当语句。 import java.io.*; public class simple public static intData=new int10; public static void main(String args) int i; int Index; Index=0; InputStreamReader ir; BufferedReader in; ir=new InputStreamReader(System.in); in=new BufferedReader(ir); try do System.out.println(“Please input

14、 the number“+ Index+“you want to sort(Exit for 0):“); String s=in.readLine(); DataIndex=Integer.parseInt(s); Index+; while(DataIndex-1!=0); catch(IOException e) System.out.println(e.getMessage(); System.out.print(“Before bubble sorting:“); for(i=0; iIndex-1; i+) System.out.print(“ “+Datai+“ “); Syst

15、em.out.println(“ “); BubbleSort(Index-1); System.out.print(“After Bubble Sorting:“); for(i=0; iIndex-1;i+) System.out.print(“ “+Datai+“ “); System.out.println(“ “); public static void BubbleSort(int Index) int i, j, k; boolean Change; int Temp; for(j=Index; j1;j-) Change=false; for(i=0; ij-1;i+) if(

16、Datai+1Datai) Temp=Datai+1; Datai+1=Datai; _; _; if(Change) System.out.print(“Current Sorting Result:“); for(k=0; kIndex; k+) System.out.print(“ “+Datak+“ “); System.out.println(“ “); (分数:40.00)_正确答案:()解析:Datai=Temp Change=true 讲解 本题考查知识点:基本排序算法。冒泡排序是最常用的交换排序方式,其核心算法就是比较和交换。交换的最简单方法是用一个中间变量作交换中介。先把其

17、中一个值存入临时变量,然后将另一个值赋给第一个值,最后将临时变量赋给另一个值(第 1 个空)。另外,为加快速度,如果排序已经完成了,就可以直接返回,而不必等待循环结束(第 2 个空,将标志变量设为真)。三、B3综合应用题/B(总题数:1,分数:30.00)3.下面是一个 Applet 程序,其功能是从 3100 之间(包括 3 和 100)每隔 0.5 秒显示一个新的数字,如果数字为素数,则显示为灰色,其他为绿色。请更正题中带下划线的部分。 注意:不改变程序的结构,不得增行或删行。 import java.awt.*; import java.applet.Applet; /* applet

18、code=“exl5_3.class“width=800 height=400 /applet */ public class ex15_3 extends Applet public Color color15_3=Color.black; private int n15_3=3; public myPrime thPrimel5_3; public void init() thPrimel5_3=new myPrime(this); thPrimel5_3.start(); public void paint(Graphics g) g.setColor(Colorl5_3); Ug.dr

19、awString(n15_3,50,50)/U; public int getInt() return n15_3; class myPrime extends Thread ex15_3 objl5_3; myPrime(ex15_3 o) this.objl5_3=o; public boolean isPrime(int n) boolean bPrime=true; int i=2; if(n3|n100) return false; while(in-1 i+; return bPrime; public void run() int i; for(i=3;Ui100/U;i+) i

20、f(isPrime(i) objl5_3.color15_3=Color.gray; else objl5_3.color15_3=Color.green; Uobj15_3.n15_3;/U objl5_3.repaint(); try sleep(500); catch(InterruptedException ie) exl5_3.html HTML HEAD TITLEexl5_3/TITLE /HEAD BODY applet code=“exl5_3.class“ width=800 height=400 /applet /BODY /HTML(分数:30.00)_正确答案:()解

21、析:String.valueOf(n15_3) i101 或 i=100 obj15_3.setInt(i) 讲解 本题主要考查线程的概念和使用,Applet 的执行过程和窗口,for 循环语句,字符串和血型的数据转换,以及面向对象编程的基本思想。解题关键是熟练地将 Applet 的执行和线程的基本思想结合,完成一定的综合性的应用;熟练掌握线程的建立、运行以及线程类与封装类之间的信息传递方式,即通过对象调用封装的方法来进行,如语句。obj15_3.repaint()。本题中,第 1 处,不可以直接填入 n15_3,会导致参数类型不符合的错误,应该用String 类的 valueOf()方法对血型数据进行转换得到 String 类型数据;第 2 处,注意题目要求,需要包括 3 和 100,因此循环变量的上界应该是 i101 或者 i100;第 3 处,由于 n15_3 是类 exl5_3 的私有成员变量,因此不可以直接用对象。obj15_3 来调用这个成员变量,需要通过类 exl5_3 的方法 setInt()来实现对私有成员变量的修改。

展开阅读全文
相关资源
猜你喜欢
  • DIN EN 61883-8-2015 Consumer audio video equipment - Digital interface - Part 8 Transmission of ITU-R BT 601 style digital video data (IEC 61883-8 2008 + A1 2014) German version EN.pdf DIN EN 61883-8-2015 Consumer audio video equipment - Digital interface - Part 8 Transmission of ITU-R BT 601 style digital video data (IEC 61883-8 2008 + A1 2014) German version EN.pdf
  • DIN EN 61904-2001 Video recording - Helical-scan digital component video cassette recording format using 12 65 mm magnetic tape and incorporating data compression (Format Digital-L.pdf DIN EN 61904-2001 Video recording - Helical-scan digital component video cassette recording format using 12 65 mm magnetic tape and incorporating data compression (Format Digital-L.pdf
  • DIN EN 61907-2010 Communication network dependability engineering (IEC 61907 2009) German version EN 61907 2010《通讯网络可靠性工程(IEC 61907-2009) 德文版本EN 61907-2010》.pdf DIN EN 61907-2010 Communication network dependability engineering (IEC 61907 2009) German version EN 61907 2010《通讯网络可靠性工程(IEC 61907-2009) 德文版本EN 61907-2010》.pdf
  • DIN EN 61909-2001 Audio recording - Minidisc system (IEC 61909 2000) German version EN 61909 2000《音频记录 小光盘系统》.pdf DIN EN 61909-2001 Audio recording - Minidisc system (IEC 61909 2000) German version EN 61909 2000《音频记录 小光盘系统》.pdf
  • DIN EN 61910-1-2016 Medical electrical equipment - Radiation dose documentation - Part 1 Radiation dose structured reports for radiography and radioscopy (IEC 61910-1 2014) German .pdf DIN EN 61910-1-2016 Medical electrical equipment - Radiation dose documentation - Part 1 Radiation dose structured reports for radiography and radioscopy (IEC 61910-1 2014) German .pdf
  • DIN EN 61915-1-2008 Low-voltage switchgear and controlgear - Device profiles for networked industrial devices - Part 1 General rules for the development of device profiles (IEC 619.pdf DIN EN 61915-1-2008 Low-voltage switchgear and controlgear - Device profiles for networked industrial devices - Part 1 General rules for the development of device profiles (IEC 619.pdf
  • DIN EN 61915-2-2015 Low-voltage switchgear and controlgear - Device profiles for networked industrial devices - Part 2 Root device profiles for starters and similar equipment (IEC .pdf DIN EN 61915-2-2015 Low-voltage switchgear and controlgear - Device profiles for networked industrial devices - Part 2 Root device profiles for starters and similar equipment (IEC .pdf
  • DIN EN 61920-2004 Infrared free air applications (IEC 61920 2004) German version EN 61920 2004《红外传输系统 大气作用》.pdf DIN EN 61920-2004 Infrared free air applications (IEC 61920 2004) German version EN 61920 2004《红外传输系统 大气作用》.pdf
  • DIN EN 61922-2003 High-frequency induction heating installations - Test methods for the determination of power output of the generator (IEC 61922 2002) German version EN 61922 2002.pdf DIN EN 61922-2003 High-frequency induction heating installations - Test methods for the determination of power output of the generator (IEC 61922 2002) German version EN 61922 2002.pdf
  • 相关搜索

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

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