欢迎来到天天文库
浏览记录
ID:54965488
大小:54.50 KB
页数:16页
时间:2020-04-25
《Java复习题(三)阅读程序题-软件.doc》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
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(i=
2、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;i3、i];System.out.println("s="+s);}}请写出该程序的输出结果:s=2603、阅读以下程序:importjava.io.*;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、++)randf.writelnt(data_arr[i]);randf.writeUTF("Goodmorning!");'for(inti=data_arr.length-l;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("Fileaccesserr5、or:"+e);}}}该程序的输出结果是:996512366Goodmorning!4、阅读以下程序并填空。class_____________________extendsException{Stringmymsg="我自己定义的异常!";doublemynum=2.0;MyException(){super("首字母不能为A!");}MyException(Stringmsg){_____________}//调用父类构造方法,参数为msgpublicvoiddisplayme(){System.out.println(mymsg);}p6、ublicdoublemymethod(){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*********");___________7、_______________;//抛出异常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(_________________8、_________){System.out.println("命令行参数个数错!");}}}程序填空:MyExceptionsuper(msg)throweMyEx
3、i];System.out.println("s="+s);}}请写出该程序的输出结果:s=2603、阅读以下程序:importjava.io.*;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、++)randf.writelnt(data_arr[i]);randf.writeUTF("Goodmorning!");'for(inti=data_arr.length-l;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("Fileaccesserr5、or:"+e);}}}该程序的输出结果是:996512366Goodmorning!4、阅读以下程序并填空。class_____________________extendsException{Stringmymsg="我自己定义的异常!";doublemynum=2.0;MyException(){super("首字母不能为A!");}MyException(Stringmsg){_____________}//调用父类构造方法,参数为msgpublicvoiddisplayme(){System.out.println(mymsg);}p6、ublicdoublemymethod(){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*********");___________7、_______________;//抛出异常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(_________________8、_________){System.out.println("命令行参数个数错!");}}}程序填空:MyExceptionsuper(msg)throweMyEx
4、++)randf.writelnt(data_arr[i]);randf.writeUTF("Goodmorning!");'for(inti=data_arr.length-l;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("Fileaccesserr
5、or:"+e);}}}该程序的输出结果是:996512366Goodmorning!4、阅读以下程序并填空。class_____________________extendsException{Stringmymsg="我自己定义的异常!";doublemynum=2.0;MyException(){super("首字母不能为A!");}MyException(Stringmsg){_____________}//调用父类构造方法,参数为msgpublicvoiddisplayme(){System.out.println(mymsg);}p
6、ublicdoublemymethod(){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*********");___________
7、_______________;//抛出异常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(_________________
8、_________){System.out.println("命令行参数个数错!");}}}程序填空:MyExceptionsuper(msg)throweMyEx
此文档下载收益归作者所有