Java复习题(三)阅读程序题-计算机(共16页).doc
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_05.gif)
《Java复习题(三)阅读程序题-计算机(共16页).doc》由会员分享,可在线阅读,更多相关《Java复习题(三)阅读程序题-计算机(共16页).doc(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 (IOExcept
2、ion e) ; for (i= n-1; i = 0; 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
3、; i+ )if (i % 3 = 0) s += ai;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) rand
4、f.seek(i*4); System,out.print( +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;
5、MyException () super(首字母不能为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();Sy
6、stem.out.println(kkkk: + e.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( _
7、) System.out.println(命令行参数个数错!); 程序填空: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;
8、class SubClass extends SuperClass 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 jav
9、a.io.*;public class abc public 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,1
10、00);max= min= a0;for(i=1; ia.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()myImag
11、e= getImage(getDocumentBase(),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(getCo
12、deBase(),image.gif); _(MalformedURLException e) public void paint(Graphics g) g.drawlmage(image,0,0,_); public void start() _();程序填空题:extends init catch this repaint10、阅读以下程序:public class Sum public static void main( String args) double sum = 0.0 ; for ( int i = 1; i= 100; i + ) sum += i;, System.ou
13、t.println( sum= + sum ); 该程序完成的功能是:求sum=1+2+3+.+100的和。11、阅读以下程序:class SuperClass int a,b; SuperClass(int x,int y) a=x; b=y; voidshow() System.out.println(a=+ a + nb=+ b); class SubClass extends SuperClass int c; SubClass(int aa,int bb,int cc) super(aa,bb);c=cc; voidshow() System.out.println(c=+ c +n
14、a=+ a +nb=+ b);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); class test public static void main(String args) SuperClass p=new SubSubClass(10,20,30);p.show();该程序的输出结果是:a=60b=20c=3012、阅读以下程序
15、:import java.io.*;publiic class Test public static void main(String args) AB s = new AB(Hello!,I love Java.);System.out.println( s.toString() ); class AB String sl; String s2; AB( String strl, String str2 ) sl = str1; s2 = str2; public String toString() return sl + s2; 该程序的输出结果是:Hello!I love Java.13
16、、阅读以下程序,并填空。import _class MyCopy public static void main(Stringo args) int ch;FileInputStream fin;_ fout;try fin = new FileInputStream(args0);fout = new FileOutputStream(_);ch = fin.read();while(ch!=-1) _ch = fin.read();fin.close(); fout.close(); catch (_ e1) System.out.println(使用格式错误!正确格式为:java myc
17、opy源文件名目标文件名);System.exit(0); catch (FileNotFoundException e3) System.out.println(文件没有找到!); catch (IOException e2) System.out.println(流错误!); 程序填空:import java.io.*;FileOutputStreamargs0fout.write(ch);ArrayIndexOutOfBoundsException14、阅读以下程序import java.io.*;public class Reverse public static void main(
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- Java 复习题 阅读 程序 计算机 16
![提示](https://www.taowenge.com/images/bang_tan.gif)
限制150内