Java程序语言试卷(A)

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

重庆大学试题单2002—2003学年第1学期2002年11月教务科制《JAVA程序语言》课程共120分钟专业级班姓名学号第1页共9页Java程序语言试卷(A)答题卡:一题:1.___________________________________________________________2.___________________________________________________________3.___________________________________________________________4.___________________________________________________________5.___________________________________________________________6.___________________________________________________________二题:位置号①②③④⑤答案位置号⑥⑦⑧⑨⑩答案三题:(R为正确,E为错误)题号(1)(2)(3)(4)(5)答案题号(6)(7)(8)(9)(10)答案题号(11)(12)(13)(14)(15)答案题号(16)(17)(18)(19)(20)答案四题:1.___________________________________________________________2.___________________________________________________________3.___________________________________________________________4.___________________________________________________________5.___________________________________________________________五题:第2页共9页一、阅读JAVA程序,写出运行结果。(30分,每小题5分)1、publicclassko5_2{publicstaticvoidmain(Stringargs[]){intx=20,y=30;if(x0)if(xy)x-=10;elsey+=10;System.out.print(x=+x);System.out.println(y=+y);}}请给出运行结果___________________________2、publicclassko5_12{publicstaticvoidmain(Stringargs[]){intt,z=10;t=sum(z);System.out.println(sum=+t);}staticintsum(intx){if(x==1)return(1);elsereturn(sum(x-1)*x);}}请给出运行结果___________________________3、interfaceko6_7interface{floatx=30.5f;floaty=4.6f;floattotal();}publicclassko6_7implementsko6_7interface{floatdollar,money;ko6_7(floata,floatb)第3页共9页{dollar=a;money=b;}publicfloattotal(){returnx*dollar+money/y;}publicstaticvoidmain(Stringargs[]){ko6_7z=newko6_7(100,4600);System.out.print(美金=+z.dollar);System.out.print(人民币=+z.money);System.out.print(折合台币=+z.total());}}请给出运行结果___________________________4、classkoA{staticinta;publicvoiddisplay(){System.out.print(“a=”+a);}}classko13{publicstaticvoidmain(Stringargs[]){koAa1=newkoA;a1.a=10;koAa2=newkoA;a2.a=20;koA.a=50;a1.dispay();a2.display();}}请给出运行结果___________________________5、classA{voidcallme(){System.out.println(“InsideA’scallme()method”);}}classBextendsA{voidcallme(){System.out.println(“InsideB’scallme()method”);}}publicclassDispatch{publicstaticvoidmain(Stringargs[]){Aa=newB();a.callme();}}第4页共9页请给出运行结果___________________________6、publicclassBubbleSort{publicstaticvoidmain(Stringargs[]){intk,j;intintArray[]={30,1,-9,70};intle=intArray.length;for(j=0;jle-1;j++)for(k=j+1;kle;k++)if(intArray[j]intArray[k]){intt=intArray[j];intArray[j]=intArray[k];intArray[k]=t;}for(j=0;jle;j++)System.out.print(intArray[j]+”“);}}请给出运行结果_________________________二、填空、请将程序(或部分程序)填写完整。(20分,每小题2分)1.运行HelloApp.javaApplet小程序的网页如下。htmlapplet__①____=HelloApp.classwidth=200height=35/applet/html2、对圆进行数据抽象,并建立类。classpoint{//定义点类pointintx0;inty0;point(intx,inty){//构造方法this.x0=x;this.y0=y;}}classcircle{//定义圆类circlepointcenter;intradius;___②_____(pointp1,intr1){//构造方法this.center=p1;this.radius=r1;}doublearea(){//定义园面积returnMath.PI*radius*radius;}第5页共9页}3、建立抽象类figure,并进一步建立矩形类。publicabstractclassfigure{publicabstractfloatarea();publicabstractfloatcircumference();}publicclassrectangle__③____figure{publicfloatd;publicrectangle(){d=11.4;}publicfloatarea(){returnd*d;}publicfloatcircumference(){return2*d;}}4、封装可以限定类中的成员只被该类本身访问:packagep1;publicclassori{//要求限定类中的成员只被该类本身访问___④____intn_p=2;voidAccess(){System.out.println(“n_p=”+n_p);}}5、String类对象的访问。ClassaccessString{Publicstaticvoidmain(Stringargs[]){Strings=”Let’slearnjavafromtheverybeginning.SeehowtoaccessaString!”;System.out.println(“ThelengthofStringis=”+s.length());System.out.println(“charatthespecifiedindex6is=”+____⑤_______);System.out.println(“Thefirstoccurrenceof‘a’is=”+s.indexOf(‘a’));//System.out.println}}6、字符串转化成简单数据类型。publicclassStringToObject{publicstaticvoidmain(Stringargs[]){第6页共9页intnInt;doubledDouble;//生成相应的数据类型StringstrInteger=newString(314);StringstrDouble=newString(3.1416);nInt=_____⑥_______(strInteger);dDouble=Double.parseDouble(strDouble);System.out.println(“简单数据类型:”+nInt+””+dDouble);}}7、例外处理及输入流的应用。importjava.io.*;publicclassko8_2{publicstaticvoidmain(Stringargs[])throwsIOException{int[]ko=newint[5];intn,a;Stringx;BufferedReaderkeyin=newBufferedReader(newInputStreamReader(System.in));System.out.print(Enteraninteger:);x=keyin.readLine();n=Integer.parseInt(x);try{a=110/n;System.out.println(此描述可能无法执行!);}catch(__________⑦_________e){System.out.println(除数为0的错误);}System.out.println(执行完catch的描述!!!);}}第7页共9页8、文件的拷贝:从命令行输入如下:D:\java2\jy\10javaFileCopy1123.txt123bak.txt程序如下:(字节流的复制)importjava.io.*;classFileCopy1{publicstaticvoidmain(Stringargs[])throwsIOException,FileNotFoundException{FileInputStreamin=newFileInputStream(args[0]);FileOutputStreamout=newFileOutputStream(args[1]);intlength;bytebuf[]=newbyte[1024];while((length=in.read(buf,0,1024))!=-1){_____⑧________(buf,0,length);}}}9、线程程序填空。classTTTest{publicstaticvoidmain(Stringargs[]){newSimpleThread(a).start();newSimpleThread(b).start();}}classSimpleThreadextendsThread{publicSimpleThread(Stringstr){super(str);}publicvoid___⑨______{for(inti=0;i6;i++){System.out.print(getName());}try{sleep((i

1 / 9
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功