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

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

1、二级 JAVA 机试-153 及答案解析(总分:100.00,做题时间:90 分钟)一、1基本操作题(总题数:1,分数:33.00)1.下列 Application 程序中,指定 as 为字符串数组类型,先创建一个 HashSet 对象并赋值,然后在屏幕输出 s,请将程序补充完整。import java.util.*;public class test17_1public static void main(String args)_s=new HashSet();s.add(“Hello“);s.add(“World“);s.add(new Character(我);s.add(new Int

2、eger(23);s.add(“Hello“);_as=“W“,“o“,“r“,“1“,“d“;s.add(as);s.add(null);s.add(new Integer(23);s.add(null);System.out.println(_);(分数:33.00)_二、2简单应用题(总题数:1,分数:33.00)2.请完成下列 Java 程序。程序的功能是复制文件并显示文件,将每个字符读入,并写入另一个文件,同时显示出来(注意:在本题中,当前目录下的 README.txt 文件打印在屏幕上,并写入另一个文件temp.txt 中)。注意:请勿改动 main()主方法和其他已有的语句内容,

3、仅在下画线处填人适当的语句。import java.io.*;public class FileCopyBypublic static void main(String args)tryFileReader input=new FileReader(“README.txt“);FileWriter output=new FileWriter(“temp.txt“);int c=input.read();while(_)_System.out.print(char)c);c=input.read();input.close();output.close();catch(IOException e

4、)Systemoutprintln(e);(分数:33.00)_三、3综合应用题(总题数:1,分数:34.00)3.下面是一个 Applet 程序,其功能是进行整数加法运算,要求有 3 个文本区域,2 个作为输入, 1 个作为输出,并且由异常处理来判断输入的数字是否为整型,如果是则进行运算,否则抛出异常并显示在第 3个文本区域中。请改正程序中的错误(有下画线的语句),使程序能输出正确的结果。注意:不改动程序的结构,不得增行或删行。import java.awt.*;import java.awt.event.*;import java.applet.Applet;/*applet code=“

5、ex17_3.class“width=800 height=400/applet*/public class ex17_3 extends Applet implements ActionListenerTextField tf1=new TextField(5);TextField tf2=new TextField(5);TextField tf3=new TextField(5);Label l1=new Label(“+“);Label l2=new Label(“=“);Button btn=new Button(“相加“);public void init()add(l1);add

6、(tf1);add(tf2);add(l2);add(tf3);add(btn);btn.addActionListener(this);public void actionPerformed(ActionEvent ae) tryint a=Integer.parseInt(tfi.getText();int b=Integer.parseInt(tf2.getText();int x=a+b;tf2.setText(Integer.toString(x);catch(NumberFormatException nfe)tf3.setText(“error!“);ex17_3.htmlHTM

7、LHEADTITLEex17_3/TITLE/HEADBODYapplet code=“ex17_3.class“width=800 height=400/applet/BODY/HTML(分数:34.00)_二级 JAVA 机试-153 答案解析(总分:100.00,做题时间:90 分钟)一、1基本操作题(总题数:1,分数:33.00)1.下列 Application 程序中,指定 as 为字符串数组类型,先创建一个 HashSet 对象并赋值,然后在屏幕输出 s,请将程序补充完整。import java.util.*;public class test17_1public static v

8、oid main(String args)_s=new HashSet();s.add(“Hello“);s.add(“World“);s.add(new Character(我);s.add(new Integer(23);s.add(“Hello“);_as=“W“,“o“,“r“,“1“,“d“;s.add(as);s.add(null);s.add(new Integer(23);s.add(null);System.out.println(_);(分数:33.00)_正确答案:(Set String s)解析:二、2简单应用题(总题数:1,分数:33.00)2.请完成下列 Java

9、程序。程序的功能是复制文件并显示文件,将每个字符读入,并写入另一个文件,同时显示出来(注意:在本题中,当前目录下的 README.txt 文件打印在屏幕上,并写入另一个文件temp.txt 中)。注意:请勿改动 main()主方法和其他已有的语句内容,仅在下画线处填人适当的语句。import java.io.*;public class FileCopyBypublic static void main(String args)tryFileReader input=new FileReader(“README.txt“);FileWriter output=new FileWriter(“t

10、emp.txt“);int c=input.read();while(_)_System.out.print(char)c);c=input.read();input.close();output.close();catch(IOException e)Systemoutprintln(e);(分数:33.00)_正确答案:(c! = -1output.write(c);)解析:三、3综合应用题(总题数:1,分数:34.00)3.下面是一个 Applet 程序,其功能是进行整数加法运算,要求有 3 个文本区域,2 个作为输入, 1 个作为输出,并且由异常处理来判断输入的数字是否为整型,如果是则

11、进行运算,否则抛出异常并显示在第 3个文本区域中。请改正程序中的错误(有下画线的语句),使程序能输出正确的结果。注意:不改动程序的结构,不得增行或删行。import java.awt.*;import java.awt.event.*;import java.applet.Applet;/*applet code=“ex17_3.class“width=800 height=400/applet*/public class ex17_3 extends Applet implements ActionListenerTextField tf1=new TextField(5);TextFiel

12、d tf2=new TextField(5);TextField tf3=new TextField(5);Label l1=new Label(“+“);Label l2=new Label(“=“);Button btn=new Button(“相加“);public void init()add(l1);add(tf1);add(tf2);add(l2);add(tf3);add(btn);btn.addActionListener(this);public void actionPerformed(ActionEvent ae) tryint a=Integer.parseInt(tf

13、i.getText();int b=Integer.parseInt(tf2.getText();int x=a+b;tf2.setText(Integer.toString(x);catch(NumberFormatException nfe)tf3.setText(“error!“);ex17_3.htmlHTMLHEADTITLEex17_3/TITLE/HEADBODYapplet code=“ex17_3.class“width=800 height=400/applet/BODY/HTML(分数:34.00)_正确答案:(add(tf1)add(l1)tf3.setText(Integer.toString(x)解析:

展开阅读全文
相关资源
猜你喜欢
相关搜索

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

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