欢迎来到天天文库
浏览记录
ID:35557636
大小:61.50 KB
页数:17页
时间:2019-03-28
《工科Java期末考试阅读程序题题库》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
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())
2、;}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,1
3、10,120};for(i=0;i4、newRandomAccessFile("temp.dat","rw");for(inti=0;i=0;i=i-2){randf.seek(i*4);System.out.print(""+randf.readInt());randf.seek(40);System.out.println(ra5、ndf.readUTF());randf.close();}catch(IOExceptione){System.out.println("Fileaccesserror:"+e);}}}该程序的输出结果是:996512366Goodmorning!4、阅读以下程序并填空。class_____________________extendsException{Stringmymsg="我自己定义的异常!";doublemynum=2.0;MyException(){super("首字母不能为A!");}MyExc6、eption(Stringmsg){_____________}//调用父类构造方法,参数为msgpublicvoiddisplayme(){System.out.println(mymsg);}17/17publicdoublemymethod(){returnMath.sqrt(mynum);}}classExceptionTest{publicstaticvoidmain(String[]args){try{if(args[O].charAt(O)=='A'){MyExceptione=newMyExce7、ption();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(_______8、___________________){System.out.println(aaa.getMessage());aaa.displayme();System.out.println(""+aaa.mymethod());}catch(__________________________){System.out.println("命令行参数个数错!");}}}程序填空:MyExcep
4、newRandomAccessFile("temp.dat","rw");for(inti=0;i=0;i=i-2){randf.seek(i*4);System.out.print(""+randf.readInt());randf.seek(40);System.out.println(ra
5、ndf.readUTF());randf.close();}catch(IOExceptione){System.out.println("Fileaccesserror:"+e);}}}该程序的输出结果是:996512366Goodmorning!4、阅读以下程序并填空。class_____________________extendsException{Stringmymsg="我自己定义的异常!";doublemynum=2.0;MyException(){super("首字母不能为A!");}MyExc
6、eption(Stringmsg){_____________}//调用父类构造方法,参数为msgpublicvoiddisplayme(){System.out.println(mymsg);}17/17publicdoublemymethod(){returnMath.sqrt(mynum);}}classExceptionTest{publicstaticvoidmain(String[]args){try{if(args[O].charAt(O)=='A'){MyExceptione=newMyExce
7、ption();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(_______
8、___________________){System.out.println(aaa.getMessage());aaa.displayme();System.out.println(""+aaa.mymethod());}catch(__________________________){System.out.println("命令行参数个数错!");}}}程序填空:MyExcep
此文档下载收益归作者所有