电脑桌面
添加小米粒文库到电脑桌面
安装后可以在桌面快捷访问

《JAVA程序设计》复习题之(三)阅读程序题VIP免费

《JAVA程序设计》复习题之(三)阅读程序题_第1页
1/17
《JAVA程序设计》复习题之(三)阅读程序题_第2页
2/17
《JAVA程序设计》复习题之(三)阅读程序题_第3页
3/17
《JAVA程序设计》复习题之(三)阅读程序题(计算机科学与技术专业使用)三、程序阅读题1.阅读以下程序importjava.io.*;publicclassReverse2{publicstaticvoidmain(Stringargs[]){inti,n=10;inta[]=newint[10];try{BufferedReaderbr=newBufferedReader(newInputStreamReader(System.in));a[i]=Integer.parseInt(br.readLine());}catch(IOExceptione){};for(i=n-1;i>=0;i=i-2)System.out.print(a[i]+"");System.out.println();}}请写出该程序的功能:该程序使用字符缓冲输入流从键盘输入10个数,然后倒序并间隔打印出来。2.阅读以下程序importjava.io.*;publicclassabc{publicstaticvoidmain(Stringargs[]){inti,s=0;inta[]={20,30,40,50,60,70,80,90,100,110,120};for(i=0;i=0;i=i-2){randf.seek(i*4);System.out.print(""+randf.readInt());randf.seek(40);System.out.println(randf.readUTF());randf.close();}catch(IOExceptione){System.out.println("Fileaccesserror:"+e);}}}该程序的输出结果是:996512366Goodmorning!4、阅读以下程序并填空。class_____________________extendsException{Stringmymsg="我自己定义的异常!";doublemynum=2.0;MyException(){super("首字母不能为A!");}MyException(Stringmsg){_____________}//调用父类构造方法,参数为msgpublicvoiddisplayme(){System.out.println(mymsg);}publicdoublemymethod(){returnMath.sqrt(mynum);}}classExceptionTest{publicstaticvoidmain(String[]args){try{if(args[O].charAt(O)=='A'){MyExceptione=newMyException();System.out.println("kkkk:"+e.mymethod());e.displayme();System.out.println("*********intry*********");__________________________;//抛出异常e}elseif(args[O].charAt(O)=='B'){thrownewMyException("第一个字符不应是B!");}else{System.out.println(args[0]);}}catch(__________________________){System.out.println(aaa.getMessage());aaa.displayme();System.out.println(""+aaa.mymethod());}catch(__________________________){System.out.println("命令行参数个数错!");}}}程序填空:MyExceptionsuper(msg)throweMyExceptionaaaArrayIndexOutOfBoundsException5、阅读以下程序importjava.io.*;publicclassTest{publicstaticvoidmain(Stringargs[]){SubSubClassm=newSubSubClass(3,6,6);m.show();}}classSuperClass{inta,b;SuperClass(intx,inty){a=x;b=y;}}classSubClassextendsSuperClass{intc;SubClass(intaa,intbb,intcc){super(aa,bb);c=cc;}}classSubSubClassextendsSubClass{inta;SubSubClass(intaa,intbb,intcc){super(aa,bb,cc);a=aa+bb+cc;}voidshow(){System.out.println("a="+a+"\nb="+b+"\nc="+c);}}请写出该程序的运行结果:a=15b=6c=66、阅读以下程序importjava.io.*;publicclassabc{publicstaticvoidmain(Stringargs[]){Stringsl="Hello!";Strings2=newString("World!");System.out.println(sl.concat(s2));}}请写出该程序的运行结果:Hello!World!7、阅读以下程序importjava.io.*;publicclassClass1{publicstaticvoidmain(Stringargs[]){inti,max,min;inta[]={12,67,8,98,23,56,124,55,99,100);max=min=a[0];for(i=1;imax)max=a[i];}System.out.println(max+""+min);System.out.println();}}请写出该程序完成的功能:在数组中查找并输出最大值和最小值。8、阅读以下程序importjava.awt.*;importjava.applet.Applet;publicclassDrawMyImageextendsApplet{Im...

1、当您付费下载文档后,您只拥有了使用权限,并不意味着购买了版权,文档只能用于自身使用,不得用于其他商业用途(如 [转卖]进行直接盈利或[编辑后售卖]进行间接盈利)。
2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。
3、如文档内容存在违规,或者侵犯商业秘密、侵犯著作权等,请点击“违规举报”。

碎片内容

《JAVA程序设计》复习题之(三)阅读程序题

确认删除?
VIP
微信客服
  • 扫码咨询
会员Q群
  • 会员专属群点击这里加入QQ群
客服邮箱
回到顶部