已阅读5页,还剩5页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
程序分析题(共6小题,每小题5分,共30分)1. 写出下面程序的运行结果。 public class ArrayExamplepublic static void main(String args) long a=2011,2012,2013,2014; long b=100,200,300,400,500; b=a; System.out.println(Length=+b.length); System.out.println(b0=+b0); 运行结果:Length=4 b0=20112. 请写出下面程序的运行结果。class MyString public String getString(String s)StringBuilder str = new StringBuilder ();for(int i = 0;i s.length();i+)if(i % 2 = 0)char c = s.charAt(i);str.append(c);return new String(str); public class StringExercise public static void main(String args) String s = ABCDEFGH;MyString ms = new MyString();System.out.println(ms.getString(s);运行结果:ACEG 3.请写出下面程序的运行结果。class EXA int add(int x,int y) return x+y; class EXB extends EXA int add(int x,int y) return x-y; public class ExtendsExercise public static void main(String args) EXA a=new EXA(); System.out.println(a.add(80,20); a=new EXB (); System.out.println(a.add(80,20); 运行结果:100 604. 请写出下面程序运行的结果。 class ex int u, v;void p2(int x, int y) int i, j;for (i=1; i=x;i+) j = y+i; System.out.print(j+ ); void p( ) u=3; v=2; p2(u, v);System.out.println();u+=v; v*=u; p2(u, v); class Exam11 public static void main(String args) ex A = new ex();A.p();运行结果:3 4 5 11 12 13 14 155. 请写出下面程序的运行结果。 public class RegexTesterpublic static void main(String args) String regex=(13d|15036-9|18089)d8$; String number1 String number2=1305516699$; String number3 String number4 System.out.println(number1.matches(regex); System.out.println(number2.matches(regex); System.out.println(number3.matches(regex); System.out.println(number4.matches(regex); 运行结果:true false true false 6. 写出下面程序的运行结果。public class Figure public int xPosition,yPosition;public void draw()System.out.println(drawing Figure);public class Rectangle extends Figurepublic void draw()System.out.println(drawing Rectangle);public class Circle extends Figurepublic void draw()System.out.println(drawing Circle); public class Testerpublic static void main(String args)Figure figures = new Figure3;figures0=new Figure();figures1=new Rectangle();figures2=new Circle();for(int i=0;ifigures.length;i+)figuresi.draw();运行结果:drawing Figure drawing Rectangle drawing Circle7. 写出下面程序的运行结果。 import java.util.*; public class ArrayTester public static void main(String args) int arrays1 = 1,3,5; int arrays2 = 2,4,6; int arrays3 = new int3; arrays2=arrays3; for(int i=0;iarrays3.length;i+) arrays3i=arrays1i; for(int i=0;iarrays2.length;i+) System.out.println(arrays2i); 运行结果:1 3 58. 写出下面程序的运行结果。public class ExceptionExample public static void main(String args)tryString str = new String();char mychars = str.toCharArray();for(int i=0;i=mychars.length;i+)System.out.print(mycharsi);if(i=mychars.length-1)System.out.println();catch(ArrayIndexOutOfBoundsException e)System.out.println(ArrayIndexOutOfBounds!);catch(Exception e)System.out.println(Exception!);finallySystem.out.println(Program End!);运行结果: ArrayIndexOutOfBounds! Program End!9. 写出下面程序的运行结果。public class Exam4 String str=new String(aust); char ch = s,s,j;public static void main(String args) Exam4 ex = new Exam4(); ex.change(ex.str,ex.ch); System.out.println(ex.str+ and); System.out.println(ex.ch); public void change(String str,char ch) str = jsjxy; ch0 = j; 运行结果:aust and jsj10. 写出下面程序的运行结果。 import java.util.*; public class CollectionTester public static void main(String args) Vector teamList = new Vector(); teamList.add(Zhang Wei);teamList.add(Liu Hong); teamList.add(Yu Hongshu); teamList.set(2,Liu Na); teamList.remove(0); teamList.remove(0); System.out.println(teamList.get(0); Hashtable ht = new Hashtable(); ht.put(key,Zhang Wei); ht.put(key,Liu Hong); Iterator its = ht.values().iterator(); while(its.hasNext() System.out.println(its.next(); 运行结果:Liu Na Liu Hong 11. 请写出下面程序的输出结果。public class Exam extends TT public static void main(String args) Exam t=new Exam (Tom.); public Exam (String s) super(s); System.out.print(How are you?); public Exam () this(I am Jack.); class TT public TT() System.out.print(Hi!); public TT(String s) this(); System.out.print(I am +s); 运行结果:Hi!I am Tom.How ar you?12. 请写出下面程序的输出结果。public class MethodParameter String str=new String(Java); char ch = A,S,P; public static void main(String args) MethodParameter ex = new MethodParameter(); ex.change(ex.str,ex.ch); System.out.print(ex.str+ and); System.out.println(ex.ch); public void change(String str,char ch) str = Android; ch0 = J; 运行结果:Java and JSP13. 写出下面程序的运行结果。 public class PhoneValidation public static void main(String args) String regex = (13d|15036-9|1889)d8$; String number = number=number.replace(5, 6); boolean match = number.matches(regex); System.out.println(number + n + match); 运行结果false14. 写出下面程序的运行结果。 import java.io.* ; public class Exam8 public static void main(String args ) int i ; int a = 11,22,33,44,55,66,77,88,99 ; for (i = 0 ; i = a.length / 2 ; i + ) System.out.print( ai+aa.length-i-1+ ); System.out.println(); 运行结果:110 110 110 110 11015. 写出下面程序运行的结果。class Exam9 public static void main(String args) people p=new graduate();class peopleString name;int age;people()people(String name,int age)=name;this.age=age;System.out.println(In people);class student extends peopleString school;student()this(null,0,null);System.out.println(In student1);student(String name,int age,String school)super(name,age);this.school=school;System.out.println(In student2);class graduate extends studentgraduate()System.out.println(In graduate);运行结果:In peopleIn student2In student1In graduate16. 写出下面程序运行的结果。public class Exam10 String str=new String(good); charch=a,b,c; public static void main(String args) Exam10 ex=new Exam10(); ex.change(ex.str,ex.ch); System.out.print(ex.str+ and ); System.out.print(ex.ch); public void change(String str,char ch) str=test ok; ch0=g; 运行结果:good and abc17. 写出下面程序运行的结果。class Employee static void expenseAllowance() System.out.println(in class Employee!); class Manager extends Employee static void expenseAllowance() System.out.println(in class Manager!); class exam12 public static void main(String args)Manager man = new Manager(); Employee emp1 = new Employee(); Employee emp2 = (Employee)man; man.expenseAllowance(); emp1.expenseAllowance(); emp2.expenseAllowance(); 运行结果:in class Manager!in class Employee!in class Employee!18. 写出下面程序的运行结果。public class ExceptionExample public static void main(String args)tryString str = new String(Thinking in Java);char mychars = str.
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- Unit6 单元重点单词词组语法短语句型专练-2023-2024学年七年级英语上册(人教版)
- 2026年中心供应室服务合同
- 护患沟通的原则与实践技巧
- 山东省聊城市2025-2026学年物理高二第一学期期末检测模拟试题含解析
- 稳派教育2025年物理高一上期末质量跟踪监视模拟试题含解析
- 刺伤足部个案护理
- 山东省六地市部分学校2025-2026学年数学高二第一学期期末学业水平测试试题含解析
- 云南工程职业学院《艺术衍生品设计》2024-2025学年第一学期期末试卷
- 上海大学附中2026届化学高一上期中预测试题含解析
- 阻塞性黄疸护理质量控制与评价
- 苗木种植承包合同
- 电除颤操作及评分标准
- 梁板结构:双向板
- 冶金物理化学相图
- 胸腔积液护理查房课件
- 2024年12月浙江省大学英语三级考试真题试卷
- T∕CFA 0308053-2019 铸造企业清洁生产要求 导则
- 老年失能全周期综合康复管理模式专家共识
- 第九单元 文人情致 课件高一音乐人音版(2019)必修 音乐鉴赏
- 未被列入违法失信名单承诺书
- 输水涵洞改造工程施工方案
评论
0/150
提交评论