Java复习题(三)阅读程序题-软件

上传人:pu****.1 文档编号:513011602 上传时间:2023-02-23 格式:DOC 页数:16 大小:77.92KB
返回 下载 相关 举报
Java复习题(三)阅读程序题-软件_第1页
第1页 / 共16页
Java复习题(三)阅读程序题-软件_第2页
第2页 / 共16页
Java复习题(三)阅读程序题-软件_第3页
第3页 / 共16页
Java复习题(三)阅读程序题-软件_第4页
第4页 / 共16页
Java复习题(三)阅读程序题-软件_第5页
第5页 / 共16页
点击查看更多>>
资源描述

《Java复习题(三)阅读程序题-软件》由会员分享,可在线阅读,更多相关《Java复习题(三)阅读程序题-软件(16页珍藏版)》请在金锄头文库上搜索。

1、JAVA程序设计复习题之(三)阅读程序题三、程序阅读题1阅读以下程序import java.io.*;public class Reverse2 public static void main(String args )int i,n=10; int a = new int10; try BufferedReader br = new BufferedReader( new InputStreamReader(System.in); ai = Integer.parseInt(br.readLine() ); catch (IOException e) ; for (i= n-1; i = 0

2、; i=i-2)System.out.print(ai+ ); System.out.println();请写出该程序的功能:该程序使用字符缓冲输入流从键盘输入10个数,然后倒序并间隔打印出来。2阅读以下程序import java.io.* ;public class abc public static void main(String args ) int i, s = 0 ; int a = 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120 ; for ( i = 0 ; i a.length ; i+ )if (i % 3 = 0) s += a

3、i;System.out.println(s= + s);请写出该程序的输出结果:s=2603、阅读以下程序:import java.io.*;public class TestRandomAccess public static void main(String args) int data_arr=65,66,56,23,27,1,43,65,4,99; try RandomAccessFile randf=new RandomAccessFile(temp.dat,rw); for (int i=0; i=0; i=i-2) randf.seek(i*4); System,out.pri

4、nt( +randf.readInt(); randf.seek(40); System.out.println(randf.readUTF(); randf.close(); catch (IOException e) System.out.println(File access error: +e); 该程序的输出结果是:99 65 1 23 66 Good morning!4、阅读以下程序并填空。class _ extends Exception String mymsg=我自己定义的异常!; double mynum = 2.0; MyException () super(首字母不能为

5、A! ); MyException (String msg)_ /调用父类构造方法,参数为 msg public void displayme() System.out.println(mymsg); public double mymethod() return Math.sqrt(mynum); class ExceptionTest public static void main(String args) try if ( argsO.charAt(O)= A) MyException e = new MyException();System.out.println(kkkk: + e.

6、mymethod();e.displayme();Systemoutprintln(*in try*); _; /抛出异常e else if(argsO.charAt(O)= B) throw new MyException (第一个字符不应是B! ); else System.out.println(args0); catch ( _ ) System.out.println(aaa.getMessage(); aaa.displayme(); System.out.println( + aaa.mymethod(); catch( _ ) System.out.println(命令行参数个

7、数错!); 程序填空:MyException super(msg)throw eMyException aaaArrayIndexOutOfBoundsException5、阅读以下程序 import java.io.*;public class Test public static void main(String args) SubSubClass m=new SubSubClass(3,6,6);m.show(); class SuperClass int a,b; SuperClass(int x,int y) a=x; b=y; class SubClass extends Supe

8、rClass int c; SubClass(int aa,int bb,int cc) super(aa,bb);c = cc; class SubSubClass extends SubClass int a; SubSubClass(int aa,int bb,int cc) super(aa,bb,cc);a = aa + bb + cc; void show() System.out.println(a=+ a +nb=+ b +nc=+ c); 请写出该程序的运行结果:a=60b=20c=306、阅读以下程序import java.io.*;public class abc pub

9、lic static void main(String args) String sl = Hello!;String s2 = new String(World!);System.out.println(sl.concat(s2); 请写出该程序的运行结果:Hello!World!7、阅读以下程序import java.io.*;public class Class1 public static void main(String args)int i,max,min;int a = 12,67,8,98,23,56,124,55,99,100);max= min= a0;for(i=1; i

10、a.length; i+)if( ai max) max = ai;System.out.println( max + + min);System.out.println(); 请写出该程序完成的功能:在数组中查找并输出最大值和最小值。8、阅读以下程序import java.awt.*;import java.applet.Applet;public class DrawMylmage extends Applet Image myImage; /定义一个图像类Image的对象myImage public void init()myImage= getImage(getDocumentBase

11、(),pica.jpg); public void paint(Graphics g) g.drawImage(myImage,0,0,this); 请写出该程序的功能:在Applet界面中显示当前文件夹下名为“pica.jpg”的图像。9、阅读以下程序并填空。import java.awt.*;import java.applet.*;import .*;public class Mypicture _ Applet Image image; public void _() try image=getlmage(new URL(getCodeBase(),image.gif); _(MalformedURLException e) public void paint(Graphics g) g.drawlmage(image,0,0,_); public void start() _();程序填空题:extends init catch this rep

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 高等教育 > 习题/试题

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号