java程序分析题(共10页).doc

上传人:飞****2 文档编号:14447229 上传时间:2022-05-04 格式:DOC 页数:10 大小:44KB
返回 下载 相关 举报
java程序分析题(共10页).doc_第1页
第1页 / 共10页
java程序分析题(共10页).doc_第2页
第2页 / 共10页
点击查看更多>>
资源描述

《java程序分析题(共10页).doc》由会员分享,可在线阅读,更多相关《java程序分析题(共10页).doc(10页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。

1、精选优质文档-倾情为你奉上程序分析题(共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 S

2、tring 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

3、(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

4、); 运行结果: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

5、. 请写出下面程序的运行结果。 public class RegexTesterpublic static void main(String args) String regex=(13d|15036-9|18089)d8$; String number1=; String number2=$; String number3=; String number4=; System.out.println(number1.matches(regex); System.out.println(number2.matches(regex); System.out.println(number3.matc

6、hes(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

7、 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 Figur

8、e 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+) Sy

9、stem.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(ArrayIndexO

10、utOfBoundsException 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(St

11、ring 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

12、) 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 =

13、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.);

14、 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();

15、 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 =

16、 ; 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 + ) Sy

17、stem.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)this.name=name;this.age=age;System.out.println(In people);cla

18、ss 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 stud

19、ent2In 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;

20、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 Manage

21、r(); 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 = ne

22、w String(Thinking in Java);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!);finally

23、System.out.println(Program End!);运行结果:Thinking in Java ArrayIndexOutOfBounds! Program End!19. 写出下面程序的运行结果。public class A private int x=100; public void setX(int x)this.x = x; public int getX()return x; public class Tester public static void method1(A a) a.setX(200); public static void method2(int x) x = 20; public static void main(String args) A a = new A(); method1(a); System.out.println(a.getX(); int n = 10; method2(n); System.out.println(n); 运行结果:200 10专心-专注-专业

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 教育专区 > 教案示例

本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知淘文阁网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

工信部备案号:黑ICP备15003705号© 2020-2023 www.taowenge.com 淘文阁