ImageVerifierCode 换一换
格式:DOCX , 页数:17 ,大小:81.31KB ,
资源ID:21625748      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/21625748.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(上海市计算机等级考试二级Java程序调试与程序填空Word文档格式.docx)为本站会员(b****6)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

上海市计算机等级考试二级Java程序调试与程序填空Word文档格式.docx

1、 g。drawImage(image,0,0, this ); 【解析】该题要求掌握如何在applet中显示图像文件的编程能力,具体可参照参考教材第十章.3。 编写removeRandChar()方法,该方法有两个参数,类型分别是String和int,第二个参数表示从第一个参数指定的字符串中删除字符的个数.删除哪个字符由随机数决定。如果第二个参数比第一个参数指定的字符串长度大,则该方法返回空字符串。removeRandChar()方法必须包括调用removeSingChar()方法,该方法定义在test4_1应用程序中。例如执行完整的test4_1应用程序两次后,产生如下的输出:C: java

2、 test4_1Remove 3 random characters from INTERESTING: INEETINGRemove 6 random characters from INTERESTING: EESTN ITERETIN IEESG下面是不包括removeRandChar()方法的test4_1应用程序: public class test4_1public static void main(String args) String word1 = removeRandChar(INTERESTING”, 3);System。out。println(”Remove 3 ran

3、dom characters from INTERESTING: + word1);word1 = removeRandChar(”INTERESTING”, 6);out.println(”Remove 6 random characters from INTERESTING: ” + word1);/*This method removes the character at position: indexNum, from the String: str,and returns the resulting String。/private static String removeSingCh

4、ar(String str, int indexNum) return str。substring(0,indexNum) + str。substring(indexNum+1);private static String removeRandChar(String str, int howMany) if (str。length() = howMany) return ”; int randNo; for(int j=0; jhowMany; j+) randNo = (int) (Math.random() str。length(); str = removeSingChar(str, r

5、andNo); return str;【解析】该题要求掌握编写方法和调用方法的能力,要注意形参的使用,以及有返回值和没有返回值的不同编写形式.4.仔细阅读下面student类的定义,该类的定义可以存放学生的姓名(name)、测验分数(testMark)和考试分数(examMark).public class Student private String name;private int testMark;private int examMark;public Student(String theName) name = theName;public Student(String theName

6、, int test, int exam) testMark = test;examMark = exam;public void setExamMark(int exam) println(name + s exam mark changed to + examMark);public int getTestMark() return testMark;public void displayInfo() System.out.println(name + ” got ” + testMark + inthe test and + examMark + in the exam”);public

7、 void compareTo(Student other) if (examMark other。examMark)println(name + ” did better than + other。name);elseout.println(name + did worse than ” + other.name);要求完成test4_3的编程,它将创建两个Student对象并调用相应的方法,产生的输出如下所示:C: java test4_3张楠 got 70 in the test and 85 in the exam李浩 got 80 in the test and 90 in the

8、exam李浩s exam mark changed to 40李浩 did worse than 张楠注意不能使用任何System。out.print() 或 System.out。println()语句,产生的输出只需简单地调用所创建的Student对象的对应方法。public class test4_3 Student student1;Student student2;student1 = new Student(”张楠, 70, 85); student2 = new Student(李浩, 80, 90); student1。displayInfo(); student2。setEx

9、amMark(40);compareTo(student1);【解析】该题考核的重点是面向对象程序设计的基本应用:对象的声明与创建,以及根据需求调用实例方法。5编写change( ) 方法,该方法有一个参数,类型为int,通过方法,计算并输出由给定参数(元)的人民币兑换成一元、两元、五元的所有方案。例如当用户输入10,执行Test4_1应用程序后,产生如下的输出:import java.io.;public class Test4_1 public static void main(String args) throws IOException int money; String str; B

10、ufferedReader buf; buf=new BufferedReader(new InputStreamReader(System。in); System。print(”Input an integer:”); str=buf。readLine(); money=Integer.parseInt(str); if (money=5 & money=100) change(money); public static void change(int num) int r1,r2,r5; for (r5=0;r5=num/5;r5+) for (r2=0;r2=num/2;r2+) r1=

11、numr55r2*2; if (r1=0)println(5:+r5+”2:”+r2+ ”+”1:”+r1);【解析】这是一个考核循环逻辑的编程题.6编写一个以字符串数组为参数的uniqueStrings()方法。该方法将打印数组中所有的字符串.若数组中有相同的字符串,则相同的字符串只打印一次。例如:执行下列语句 String words = ”one,”twotwo”,”three”,”threethree”,one”;uniqueStrings(words);将输出如下: one two threeprivate static void uniqueStrings(String words

12、) for (int i = 0; i words.length; i+) boolean unique = true;for (int j = 0; j i; j+) if (wordsi。equals(wordsj)unique = false;if (unique)println(wordsi);【解析】注意形参是数组的编程,以及字符串的比较要使用equals方法7现有一段30米长的木材,每天锯去其中的一半,编程序计算并输出多少天后,木材的长度开始小于0。05米。 public static void main(String args) int d=0; float m=30; whil

13、e (m=0.05) m=m/2; d+;out.print(d+”: ”); /可选 System.out。println(m); /可选print(”You need ”+d+” days”);【解析】该题的循环只能使用while和do while语句8完成下面的程序:编写带两个参数,返回值为字符串的方法randomLetters(String word, int howMany)。该方法实现从字符串中随机获取所需数量的字符,并按获取的次序以大写字符串返回。第一个参数代表给定的字符串,第二个参数确定字符个数。(假定调用方法时字符串参数不为空,整型参数不为负)执行完整的程序后:public

14、class Test4_2 public static void main(String args) println(randomLetters(LOVELY”,3);out.println(randomLetters(”LOVELY”,3);System.out。println(randomLetters(”LOVELY,4);zhang”,1);out.println(randomLetters(”zhang”,2);private static String randomLetters ( String word, int howMany ) 其中一种输出如下: LYO VLO OOLE

15、ZGHprivate static String randomLetters ( String word, int howMany ) String outWord = ”; char c; int random; word = word.toUpperCase(); for( int i=0; ihowMany; i+ ) random = (int)( Math。random()word。length() ); c = word。charAt( random ); outWord = outWord + c; return outWord;9完成下面的程序:编写一个参数为二维整数数组、返回

16、值为整数的方法countOdds。该方法计算二维数组中奇数的个数并返回.下面的例子是一个数组的定义并调用该方法及输出对应的结果。 int twoArray = 5, 7, 8, 22, 47, 42, 75, 58, 21, 36;out.println(”Odds:+countOdds(twoArray);以上程序的结果是:Odds: 5 private static int countOdds(int theInts)int numOdds = 0;for(int i=0; i theInts.length; i+)for(int j=0; jtheIntsi。length;if (the

17、Intsij 2 != 0)numOdds+;return numOdds;【解析】要注意两维数组中不同维调用length的差别10在下图所示的小应用程序用户界面上有两个标签(Label)、一个列表框(Choice)和一个文本区域(TextArea)。程序实现以下功能:一旦用户在列表框中(单击鼠标)选择了某书名选项,该书名将被立即显示在文本区域中。请完成该程序的init()方法以实现程序的功能。awt。*;event.*;import java.applet.*;public class MyChoice extends Applet String bookstore = ”Java程序设计”

18、,C+程序设计,”网络基础,”计算机应用基础”,Visual Basic程序设计,动画设计基础” ; Label la1=new Label(”请选择你要的书籍:”); Label la2=new Label(你的选择是: TextArea t=new TextArea(5,30); Choice c=new Choice();public void init() / 所需要编写的程序块class CL implements ItemListener public void itemStateChanged(ItemEvent e) t。append(c。getSelectedItem()+”

19、n);t。setEditable(false); (该语句任选) for(int i = 0; i 6; i+) c。addItem(bookstorei);add(la1);add(c);add(la2);add(t);c.addItemListener(new CL();【解析】该题的重点是认清applet中的init方法的基本作用:对相关内容进行初始化。该题是对组件进行初始化:添加组件,设置侦听能力11。 从“C:素材库”中取出StringStrip。java文件,在该文件基础上进行补充,完成其中方法static String strip(String s,char c)的编写。该方法的

20、功能是:将指定的字母从给定的字符串中所有出现的地方移去,其中参数s是给定的字符串,参数c是指定的字母。要求用循环语句实现。下图中给出了一个从给定字符串“ABCADaAADFaRAGA”中移去A字符后为“BCDaDFaRG”的演示结果)。程序完成后将程序编辑及运行所需要的所有文件(包括源程序文件、字节码文件)存放到C:KS目录下。static String strip(String s,char c) int n=s。length(); String a=”; int i=0; while(in) char sc=s。charAt(i); if(sc=c) i+; else a=a+sc;i+;

21、; return a;【解析】从2008年开始Java等级考试采用了上机形式。因此参加考试的同学需要从指定的文件夹中取出指定的文件进行编程。希望同学打开文件后马上存放到另一个指定文件夹如本题要求的C:KS文件夹中,以免你的修改影响到原始的文件,有利于你需要时还可以取用最原始的文件.原始文件中已存放了一些文件编程所需要的非考核重点的程序段,内容有多,有少,便于程序调试.12。 从“C:素材库”中取出Division.java文件,在该文件基础上进行补充,完成简单除法计算器(只做整数除法,结果也取整数)的小应用程序编写。运行结果见图1,显示结果的文本域设置为不可编辑。当除数为0时,能抛出Arith

22、meticException异常,并在捕获异常处对异常进行处理,异常处理要求在屏幕上显示“除数不能为0,请重新输入,结果见图2.程序完成后将程序编辑及运行所需要的所有文件(包括源程序文件、字节码文件及html文件)存放到C:图1图2;import java.awt.event。public class Division extends Applet implements ActionListener Label l1,l2,E; TextField input1,input2,output1; int a,b,c; Panel p=new Panel(); public void init()

23、 setLayout(new BorderLayout(); input1=new TextField(5); l1=new Label( input2=new TextField(5); l2=new Label(”); output1=new TextField(9); E=new Label(); E。setAlignment(Label。CENTER); E.setForeground(Color.red); p。add (input1); p.add (l1);add (input2);add (l2); p.add (output1); add(North”,p); add(”Ce

24、nter”,E); input2。addActionListener(this); output1。 public void actionPerformed(ActionEvent e) a=Integer.parseInt(input1.getText(); b=Integer。parseInt(input2。getText();setText(”); try c=a/b; output1.setText(Integer。toString(c); catch (ArithmeticException e1) String Tx=”除数不能为0,请重新输入”; E.setText(Tx); o

25、utput1.setText(” 【解析】以上参考程序中非加粗的内容就是原始文件所提供的。该题的知识点有两部分:组件的设置,即界面的设计,以及事件的编程13从”C:素材库”中取出Test5.java文件,在该文件基础上进行补充,完成所需内容的编写。该applet程序中,窗口区有一个”变色”按钮,程序初始状态见下图1,在中心位置有一个半径为30的蓝色圆。(14分)当单击窗口的任意位置,在鼠标位置将显示一个圆,其颜色和大小随机而变,但半径不能超过150,见下图2;(10分)当单击”变色”按钮则圆的颜色也会随机变化.颜色有Color.red、Color.blue、Color.yellow。以下图示是用Java开发包直接运行的显示效果,仅作参考。可根据需要在”C:素材库”中选取Test5。html文件.(2分) 图 1 图2event。;import java.applet。App

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1