欢迎来到天天文库
浏览记录
ID:57662428
大小:15.42 KB
页数:28页
时间:2020-08-31
《java复习题(三)阅读程序题软件.docx》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、《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(
2、i=n-1;i>=0;i=i-2)}}请写出该程序的功能:该程序使用字符缓冲输入流从键盘输入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;i3、o.*;publicclassTestRandomAccess{publicstaticvoidmain(Stringargs[]){intdata_arr[]={65,66,56,23,27,1,43,65,4,99};try{RandomAccessFilerandf=newRandomAccessFile("temp.dat","rw");for(inti=0;i4、nti=data_arr.length-l;i>=0;i=i-2){randf.seek(i*4);System,out.print(""+randf.readInt());randf.seek(40);randf.close();}catch(IOExceptione){}}}该程序的输出结果是:996512366Goodmorning!4、阅读以下程序并填空。class_____________________extendsException{Stringmymsg="我自己定义的异常!";doublemynum=2.0;MyExce5、ption(){super("首字母不能为A!");}MyException(Stringmsg){_____________}//调用父类构造方法,参数为msgpublicdoublemymethod(){returnMath.sqrt(mynum);}}classExceptionTest{publicstaticvoidmain(String[]args){try{if(args[O].charAt(O)=='A'){MyExceptione=newMyException();e.displayme();System.out.pri6、ntln("*********intry*********");__________________________;//抛出异常e}elseif(args[O].charAt(O)=='B'){thrownewMyException("第一个字符不应是B!");}catch(__________________________){aaa.displayme();}catch(__________________________){}}}程序填空:MyExceptionsuper(msg)throweMyExceptionaaaArray7、IndexOutOfBoundsException5、阅读以下程序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(a8、a,bb);c=cc;}}classSubSubClassextendsSubClass{inta;SubSubClass(intaa,intbb,intcc){super(aa,bb,cc)
3、o.*;publicclassTestRandomAccess{publicstaticvoidmain(Stringargs[]){intdata_arr[]={65,66,56,23,27,1,43,65,4,99};try{RandomAccessFilerandf=newRandomAccessFile("temp.dat","rw");for(inti=0;i4、nti=data_arr.length-l;i>=0;i=i-2){randf.seek(i*4);System,out.print(""+randf.readInt());randf.seek(40);randf.close();}catch(IOExceptione){}}}该程序的输出结果是:996512366Goodmorning!4、阅读以下程序并填空。class_____________________extendsException{Stringmymsg="我自己定义的异常!";doublemynum=2.0;MyExce5、ption(){super("首字母不能为A!");}MyException(Stringmsg){_____________}//调用父类构造方法,参数为msgpublicdoublemymethod(){returnMath.sqrt(mynum);}}classExceptionTest{publicstaticvoidmain(String[]args){try{if(args[O].charAt(O)=='A'){MyExceptione=newMyException();e.displayme();System.out.pri6、ntln("*********intry*********");__________________________;//抛出异常e}elseif(args[O].charAt(O)=='B'){thrownewMyException("第一个字符不应是B!");}catch(__________________________){aaa.displayme();}catch(__________________________){}}}程序填空:MyExceptionsuper(msg)throweMyExceptionaaaArray7、IndexOutOfBoundsException5、阅读以下程序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(a8、a,bb);c=cc;}}classSubSubClassextendsSubClass{inta;SubSubClass(intaa,intbb,intcc){super(aa,bb,cc)
4、nti=data_arr.length-l;i>=0;i=i-2){randf.seek(i*4);System,out.print(""+randf.readInt());randf.seek(40);randf.close();}catch(IOExceptione){}}}该程序的输出结果是:996512366Goodmorning!4、阅读以下程序并填空。class_____________________extendsException{Stringmymsg="我自己定义的异常!";doublemynum=2.0;MyExce
5、ption(){super("首字母不能为A!");}MyException(Stringmsg){_____________}//调用父类构造方法,参数为msgpublicdoublemymethod(){returnMath.sqrt(mynum);}}classExceptionTest{publicstaticvoidmain(String[]args){try{if(args[O].charAt(O)=='A'){MyExceptione=newMyException();e.displayme();System.out.pri
6、ntln("*********intry*********");__________________________;//抛出异常e}elseif(args[O].charAt(O)=='B'){thrownewMyException("第一个字符不应是B!");}catch(__________________________){aaa.displayme();}catch(__________________________){}}}程序填空:MyExceptionsuper(msg)throweMyExceptionaaaArray
7、IndexOutOfBoundsException5、阅读以下程序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(a
8、a,bb);c=cc;}}classSubSubClassextendsSubClass{inta;SubSubClass(intaa,intbb,intcc){super(aa,bb,cc)
此文档下载收益归作者所有