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

上传人:terrorscript155 文档编号:1326481 上传时间:2019-10-17 格式:DOC 页数:7 大小:39KB
下载 相关 举报
【计算机类职业资格】二级JAVA机试-155及答案解析.doc_第1页
第1页 / 共7页
【计算机类职业资格】二级JAVA机试-155及答案解析.doc_第2页
第2页 / 共7页
【计算机类职业资格】二级JAVA机试-155及答案解析.doc_第3页
第3页 / 共7页
【计算机类职业资格】二级JAVA机试-155及答案解析.doc_第4页
第4页 / 共7页
【计算机类职业资格】二级JAVA机试-155及答案解析.doc_第5页
第5页 / 共7页
点击查看更多>>
资源描述

1、二级 JAVA 机试-155 及答案解析(总分:100.00,做题时间:90 分钟)一、1基本操作题(总题数:1,分数:30.00)1.下列程序中,要求按照从小到大的顺序输出 1100 之间所有能被 7 整除的数字,请将下列程序补充完整。注意:请勿改动 main()主方法和其他已有语句内容,仅在横线处填入适当语句。public class Example1_3public static void main(String argv)int i = 1;_if(_)System.out.print(i+ “,“);_while(i 100);System.out.println();(分数:30.

2、00)_二、2简单应用题(总题数:1,分数:40.00)2.请完成以下程序,首先由一个类 Example2_3 实现 Serializable 接口,并有三个成员变量,分别为 int型、double 型和 String 型,可以用 toString 的方法显示这三个成员变量。在 main 方法中创建这个Example2_3 的持久对象,根据用户在命令行输入的三个参数来设定其中成员变量的值。然后,将这个对象写入名为 TheSerial.data 的文件,并显示成员变量。最后从文件 TheSerial.data 中读出三个成员变量并显示出来。注意:请勿改动 main()主方法和其他已有语句内容,仅

3、在横线处填入适当语句。import java.io.*;class TheSerial implements Serializableprivate int intValue;private double doubleValue;private String string;TheSerial()intValue = 123;doubleValue = 12.34;string = “Serialize Test“;public void setDouble(double d)doubleValue = d;public void setInt(int i)intValue = i;public

4、 void setString(String s)string = s;public String toString()return(“int=“+intValue+“double=“+doubleValue+“ string=“+string);public class Example2_3public static void main(String argv)TheSerial e1 = new TheSerial();TheSerial e2;trye1.setInt(Integer.parseInt(argv0);e1.setDouble(Double.parseDouble(argv

5、1);e1.setStringargv2);catch(Exception e)e1.setString(e.getMessage);System.out.println(e1);tryFileOutputStream oS = new FileOutputStream(“TheSerial.data“);ObjectOutputStream oIS = new ObjectOutputStream(oS);_;catch(IOException ioException)System.out.println(ioException.getMessage();tryFileInputStream

6、 iS = new FileInputStream(“TheSerial. data“);ObjectInputStream oIS = new ObjectInputStream(iS);_System.out.println(e2);catch(IOException ioException)System.out.println(ioException.getMessage();catch(ClassNotFoundException cnfException)System.out.println(cnfException.getMessage();(分数:40.00)_三、3综合应用题(

7、总题数:1,分数:30.00)3.在以下程序中,鼠标单击小应用程序的某一点,则会在该点显示一个图标,如果双击,则会清除该图标。且在浏览器的状态栏上会显示鼠标单击位置的坐标。运行结果如下图所示。请改正程序中的错误(有下划线的语句),使程序能输出正确的结果。(分数:30.00)_二级 JAVA 机试-155 答案解析(总分:100.00,做题时间:90 分钟)一、1基本操作题(总题数:1,分数:30.00)1.下列程序中,要求按照从小到大的顺序输出 1100 之间所有能被 7 整除的数字,请将下列程序补充完整。注意:请勿改动 main()主方法和其他已有语句内容,仅在横线处填入适当语句。publi

8、c class Example1_3public static void main(String argv)int i = 1;_if(_)System.out.print(i+ “,“);_while(i 100);System.out.println();(分数:30.00)_正确答案:(doi7=0i+;或者 i=i+1;或者 i+=1;)解析:解析 本题主要考查 Java 编程的流程控制。 Java 语言中的流程控制主要是通过循环、分支和跳转三种语句来实现的。在解这类题型的时候,首先要分清楚题中要考查的语句类型,比如本题考查了考生对 do-while 循环的掌握情况;然后,再根据对应的

9、类型,看题中的语句结构是否完整。题中变量 i 从 1循环增加到 99,每一个数字模 7,如果余数为 0 就认为这是一个可以被 7 整除的数。本题中,do-while 循环缺少了“do”这个循环开始语句,因此第一个空需要填写“do”以使循环体完整;最后也是最重要的,循环一定要保证能够正常结束,许多编程经验丰富的人也会因为一时大意而写出死循环来,这样的错误一定要避免。第二个空就是使 i 值顺序增加,直到 i=100 时程序退出循环。本题中还考查了考生对条件分支语句的掌握,即 if 语句。在解条件分支语句的题的时候,首先要找出需要满足的条件是什么,需要通过分支语句分流的条件是什么。比如题中要求能被

10、7 整除,所谓整除就是余数为 0,这样我们就知道,分支条件就是余数值是否为 0,则第二个空应该填写“i7=0”。二、2简单应用题(总题数:1,分数:40.00)2.请完成以下程序,首先由一个类 Example2_3 实现 Serializable 接口,并有三个成员变量,分别为 int型、double 型和 String 型,可以用 toString 的方法显示这三个成员变量。在 main 方法中创建这个Example2_3 的持久对象,根据用户在命令行输入的三个参数来设定其中成员变量的值。然后,将这个对象写入名为 TheSerial.data 的文件,并显示成员变量。最后从文件 TheSer

11、ial.data 中读出三个成员变量并显示出来。注意:请勿改动 main()主方法和其他已有语句内容,仅在横线处填入适当语句。import java.io.*;class TheSerial implements Serializableprivate int intValue;private double doubleValue;private String string;TheSerial()intValue = 123;doubleValue = 12.34;string = “Serialize Test“;public void setDouble(double d)doubleVa

12、lue = d;public void setInt(int i)intValue = i;public void setString(String s)string = s;public String toString()return(“int=“+intValue+“double=“+doubleValue+“ string=“+string);public class Example2_3public static void main(String argv)TheSerial e1 = new TheSerial();TheSerial e2;trye1.setInt(Integer.

13、parseInt(argv0);e1.setDouble(Double.parseDouble(argv1);e1.setStringargv2);catch(Exception e)e1.setString(e.getMessage);System.out.println(e1);tryFileOutputStream oS = new FileOutputStream(“TheSerial.data“);ObjectOutputStream oIS = new ObjectOutputStream(oS);_;catch(IOException ioException)System.out

14、println(ioException.getMessage();tryFileInputStream iS = new FileInputStream(“TheSerial. data“);ObjectInputStream oIS = new ObjectInputStream(iS);_System.out.println(e2);catch(IOException ioException)System.out.println(ioException.getMessage();catch(ClassNotFoundException cnfException)System.out.pr

15、intln(cnfException.getMessage();(分数:40.00)_正确答案:(oOS.writeObject(e1)e2=(TheSerial)oIS.readObject()解析:解析 本题主要考查串行化相关的方法和实现。解题中首先要掌握串行化的基本过程和反串行化的过程。串行化过程首先要创建一个输出流 FileOutputStream,通过该类的实例对文件进行访问,然后创建一个 ObJectOutput Stream 对象,通过 writeObject()方法来实现对象的序列化。第一个空就是使用writeObject()实现序列化。反序列化过程中用 FileInputSt

16、ream 对象建立读取文件的连接,并使用该对象创建一个 ObiectInputStream 的实例,这个 ObjectInput Stream 实例的 readObject()方法就可以实现对象的反序列化。第二个空就是使用 readObject()实现反序列化。三、3综合应用题(总题数:1,分数:30.00)3.在以下程序中,鼠标单击小应用程序的某一点,则会在该点显示一个图标,如果双击,则会清除该图标。且在浏览器的状态栏上会显示鼠标单击位置的坐标。运行结果如下图所示。请改正程序中的错误(有下划线的语句),使程序能输出正确的结果。(分数:30.00)_正确答案:(displayIm=getIma

17、ge(getDocumentBase(),“ms.jpg“)第一处也可改作 displayIm=getImage(getCodeBase(),“ms.jpg“)g.clearRect(xPoint,yPoint,60,60)repaint()解析:解析 Applet 获得图像有两种方式,一种是 getImage(URL url),另一种是 getImage(URL url, String name)。init()方法用来初始化小应用程序,首先是将图像文件读入内存,然后为小应用程序添加鼠标点击事件。paint()方法向页面绘制图像,题中的 if-else 语句表示用户单击鼠标则在鼠标单击的位置显

18、示图片,用户多次点击鼠标,则清除该点右下方长宽均为 60 的矩形区域内的图像。SClickMouse 实现了鼠标监听器。mouseClicked 中获取鼠标点击的位置和点击的次数。mousePressed 方法获得鼠标按下的坐标,并将坐标值显示在状态栏中。第一种方法所使用的 URL 必须是包含图像文件名的绝对 URL,所以本处不能填使用文件名作参数。采用第二种获得图像的方式时,如果图像和 Applet 在同一文件夹可使用 getCodeBase()获得相应的 URL,当图像和 Applet 所属的 HTML 文件在同一文件夹时,可以采用 getDocumentBase()获得相应的 URL。所以第一个错误可以改为 getDocument Base(),也可以改为 getCodeBase()。第二处错误,Graphics 对象作图时,可以使用 clearRect()方法清除某一个区域的图形,而 fillRect()方法只是根据当前颜色(本题中为黑色)画出一个实心矩形。在程序要求 Applet 绘制图形时,只能调用repaint()方法,此方法会自动调用 paint()方法。故第三个错误应该改成 repaint()方法。

展开阅读全文
相关资源
猜你喜欢
  • SIS SS-ETS 300 089-1992 Integrated Services Digital Network (ISDN)  Calling Line Identification Presentation (CLIP) supplementary service  Service description《无线电设备和系统 陆地移动服务 主要用于模.pdf SIS SS-ETS 300 089-1992 Integrated Services Digital Network (ISDN) Calling Line Identification Presentation (CLIP) supplementary service Service description《无线电设备和系统 陆地移动服务 主要用于模.pdf
  • SIS SS-ETS 300 090-1992 Integrated Services Digital Network (ISDN)  Calling Line Identification Restriction (CLIR) supplementary service  Service description《综合业务数字网(ISDN)呼叫线识别限制(C.pdf SIS SS-ETS 300 090-1992 Integrated Services Digital Network (ISDN) Calling Line Identification Restriction (CLIR) supplementary service Service description《综合业务数字网(ISDN)呼叫线识别限制(C.pdf
  • SIS SS-ETS 300 094-1994 Integrated Services Digital Network (ISDN)  Connected Line Identification Presentation (COLP) supplementary service  Service description《综合业务数字网(ISDN)通话线路验证.pdf SIS SS-ETS 300 094-1994 Integrated Services Digital Network (ISDN) Connected Line Identification Presentation (COLP) supplementary service Service description《综合业务数字网(ISDN)通话线路验证.pdf
  • SIS SS-ETS 300 095-1992 Integrated Services Digital Network (ISDN)  Connected Line Identification Restriction (COLR) supplementary service  Service description《综合业务数字网(ISDN)连接线识别限制.pdf SIS SS-ETS 300 095-1992 Integrated Services Digital Network (ISDN) Connected Line Identification Restriction (COLR) supplementary service Service description《综合业务数字网(ISDN)连接线识别限制.pdf
  • SIS SS-ETS 300 100-1992 Integrated Services Digital Network (ISDN)  Routing in support of ISUP Version 1 services《综合业务数字网(ISDN)支持ISUP版本1服务的通路指示》.pdf SIS SS-ETS 300 100-1992 Integrated Services Digital Network (ISDN) Routing in support of ISUP Version 1 services《综合业务数字网(ISDN)支持ISUP版本1服务的通路指示》.pdf
  • SIS SS-ETS 300 102-1-1991 Integrated Services Digital Network (ISDN)  User-network interface layer 3  Specrfica- tions for basic call control《综合业务数字网(ISDN)用户网络接口层3 基本通话控制规范》.pdf SIS SS-ETS 300 102-1-1991 Integrated Services Digital Network (ISDN) User-network interface layer 3 Specrfica- tions for basic call control《综合业务数字网(ISDN)用户网络接口层3 基本通话控制规范》.pdf
  • SIS SS-ETS 300 102-2-1991 Integrated Services Digital Network (ISDN)  User-network interface layer 3  Specifica- tions for basic call control  Specification Description Language (S.pdf SIS SS-ETS 300 102-2-1991 Integrated Services Digital Network (ISDN) User-network interface layer 3 Specifica- tions for basic call control Specification Description Language (S.pdf
  • SIS SS-ETS 300 103-1991 Integrated Services Digital Network (ISDN)  Support of CCITT Recommendations X 21 X 21 bis and X 20 bis based Data Terminal Equipment (DTE) by an ISDN  Syncun.pdf SIS SS-ETS 300 103-1991 Integrated Services Digital Network (ISDN) Support of CCITT Recommendations X 21 X 21 bis and X 20 bis based Data Terminal Equipment (DTE) by an ISDN Syncun.pdf
  • SIS SS-ETS 300 104-1991 Integrated Services Digital Network (ISDN)  Attachment requirements for terminal equipment to connect to an ISDN using ISDN basic access  Layer 3 aspects《综合.pdf SIS SS-ETS 300 104-1991 Integrated Services Digital Network (ISDN) Attachment requirements for terminal equipment to connect to an ISDN using ISDN basic access Layer 3 aspects《综合.pdf
  • 相关搜索

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

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