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

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

1、国家二级( JAVA)机试模拟试卷 27及答案与解析 一、基本操作题( 30分) 1 下列 Application程序中,指定 as为字符串数组类型,先创建一个 HashSet对象并赋值,然后在屏幕输出 s,请将程序补充完整。 import java.util.*; public class test17_1 public static void main(String args) _s=new HashSet(); s.add(“Hello“); s.add(“World“); s.add(new Character(我 ); s.add(new Integer(23); s.add(“He

2、llo“); _as=“W“,“o“,“r“,“1“,“d“; s.add(as); s.add(null); s.add(new Integer(23); s.add(null); System.out.println(_); 二、简单应用题( 40分) 2 下列 Application程序输入一个整数,求出它的所有因子,请根据注释,将程序补充完整。 public class test19_2 public static void main(String args)throws IOException int n; /下面 7行语句的作用是从键盘输入 n的值 InputStreamReade

3、r ir; BufferedReader in; ir=new lnputStreamReader(System.in); in=new BufferedReader(ir); System out println(“Input n is: “); String s=in._; /读取 1行字符 n=Integer.parseInt(s); /下面求 n的所有因子 _(int i=1; i=n; i+) if(n%i!=0) _; /跳过打印语句回到循环起始 System out print(i+”); System out print(“n”); 三、综合应用题( 30分) 3 下面是一个

4、Applet程序,其功能是通过两个文本框获得用户输入的两个数,按回车键计算这两个数的商。请改正程序中的错误 (有下画线的语句 ),使程序能 输出正确的结果。 注意:不改动程序的结构,不得增行或删行。 import java awt *; import java awt Event *; import java applet *; /* */ public class ex18_3 extends Applet private TextField tf1, tf2; private String strAnswer; public void init() tf1=new TextField(20

5、); add(tf1); tf2=new TextField(20); add(tf2); strAnswer=“Undefined“; public void paint(Graphics g) Font f=new Font(“TimesRoman“, Font PLAIN, 20); g setFont(f); g drawstring(“商: ”, 80, 100); g drawstring(strAnswer, 60, 150); public boolean action(Event e, Object O) String s1=tf1.getText( ); String s2

6、=tf2.getText( ); try int n1=String.valueOf(s1); int n2=String.valueOf(s2); int out=n1/n2; strAnswer=InteSer.parseInt(out); catch(NamberFormatEXCeption nfe) strAnswer=“不存在的数 !”; repaint( ); return true; ex18_3 html HTML HEAD TITLE eX18_3 /TITLE /HEAD BODY applet Code=“eX18_3.class“width=800 height=400 /applet /BODY /HTML 国家二级( JAVA)机试模拟试卷 27答案与解析 一、基本操作题( 30分) 1 【正确答案】 Set String s 二、简单应用题( 40分) 2 【正确答案】 readLine( ) for continue 三、综合应用题( 30分) 3 【正确答案】 Integer.parseInt(s1) Integer.parseInt(s2) String.valueOf(out)

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

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

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