1、Java复习题阅读程序题软件JAVA程序设计复习题之(三)阅读程序题三、程序阅读题1阅读以下程序import .*;public class Reverse2 public static void main(String args ) int i,n=10; int a = new int10; try BufferedReader br = new BufferedReader( new InputStreamReader); ai = () ); catch (IOException e) ; for (i= n-1; i = 0; i=i-2) ); 请写出该程序的功能:该程序使用字符缓
2、冲输入流从键盘输入10个数,然后倒序并间隔打印出来。2阅读以下程序import .* ;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 ; i+ ) if (i % 3 = 0) s += ai; s= + s); 请写出该程序的输出结果:s=2603、阅读以下程序:import .*;public class TestRandomAccess public s
3、tatic void main(String args) int data_arr=65,66,56,23,27,1,43,65,4,99; try RandomAccessFile randf=new RandomAccessFile(,rw); for (int i=0; i=0; i=i-2) (i*4); System,( +(); (40); (); catch (IOException e) File access error: +e); 该程序的输出结果是:99 65 1 23 66 Good morning!4、阅读以下程序并填空。class _ extends Excepti
4、on String mymsg=我自己定义的异常!; double mynum = ; MyException () super(首字母不能为A! ); MyException (String msg)_ harAt(O)= A) MyException e = new MyException();kkkk: + ();();Systemoutprintln(*in try*); _; harAt(O)= B) throw new MyException (第一个字符不应是B! ); else catch ( _ ) (); + (); catch( _ ) 命令行参数个数错!); 程序填空:
5、MyException super(msg)throw eMyException aaaArrayIndexOutOfBoundsException5、阅读以下程序 import .*;public class Test public static void main(String args) SubSubClass m=new SubSubClass(3,6,6); (); class SuperClass int a,b; SuperClass(int x,int y) a=x; b=y; class SubClass extends SuperClass int c; SubClass(
6、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() a=+ a +nb=+ b +nc=+ c); 请写出该程序的运行结果:a=60b=20c=306、阅读以下程序import .*;public class abc public static void main(String args) String sl = H
7、ello!; String s2 = new String(World!); 请写出该程序的运行结果:Hello!World!7、阅读以下程序import .*;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; i+) if( ai max) max = ai; max + + min); 请写出该程序完成的功能:在数组中查找并输出最大值和最小值。8、阅读以下程序imp
8、ort .*;import class DrawMylmage extends Applet Image myImage; ;import .*;import .*;public class Mypicture _ Applet Image image; public void _() try image=getlmage(new URL(getCodeBase(),); _(MalformedURLException e) public void paint(Graphics g) (image,0,0,_); public void start() _(); 程序填空题:extends i
9、nit catch this repaint10、阅读以下程序:public class Sum public static void main( String args) double sum = ; for ( int i = 1; i= 100; i + ) sum += i;, sum= + sum ); 该程序完成的功能是:求sum=1+2+3+.+100的和。11、阅读以下程序:class SuperClass int a,b; SuperClass(int x,int y) a=x; b=y; voidshow() a=+ a + nb=+ b); class SubClass
10、extends SuperClass int c; SubClass(int aa,int bb,int cc) super(aa,bb); c=cc; voidshow() c=+ c +na=+ 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() a=+ a +nb=+ b +nc=+ c); class test public static void main(String args)
11、 SuperClass p=new SubSubClass(10,20,30); (); 该程序的输出结果是:a=60b=20c=3012、阅读以下程序:import .*;publiic class Test public static void main(String args) AB s = new AB(Hello!,I love Java.); () ); class AB String sl; String s2; AB( String strl, String str2 ) sl = str1; s2 = str2; public String toString() return
12、 sl + s2; 该程序的输出结果是:Hello!I love Java.13、阅读以下程序,并填空。import _class MyCopy public static void main(Stringo args) int ch; FileInputStream fin; _ fout; try fin = new FileInputStream(args0); fout = new FileOutputStream(_); ch = (); while(ch!=-1) _ ch = (); (); (); catch (_ e1) 使用格式错误!正确格式为:java mycopy源文件
13、名目标文件名); (0); catch (FileNotFoundException e3) 文件没有找到!); catch (IOException e2) 流错误!); 程序填空:import .*;FileOutputStreamargs0(ch);ArrayIndexOutOfBoundsException14、阅读以下程序import .*;public class Reverse public static void main(String args) int i,n=10; int a = new int10; for(i=0; in; i+) try BufferedReade
14、r br= new BufferedReader( new InputStreamReader); ai=(); ;public class Test public static void main(String args ) int i, s = 0; int a = 10, 20, 30, 40, 50, 60, 70, 80, 90; for ( i = 0 ; i ; i+ ) if(ai % 3 = 0) s += ai; s= + s); 请写出此程序的输出结果:s=18016、阅读以下程序(提示:注意同步)class One synchronized void display(i
15、nt num) two + num); try (1000); catch (InterruptedException e) 中断”); 完成”); class Two implements Runnable int number; One one; Thread t; public Two(One one_num, int n) one = one_num; number = n; t = new Thread(this); (); public void run() (number); public class Synch public static void main(String ar
16、gs) throws InterruptedException One one = new One(); int digit = 100; Two s1 = new Two(one,digit); Two s2 = new Two(one,digit); Two s3 = new Two(one,digit); Two s4 = new Two(one,digit); Synch结束!); 此程序的输出结果是:two 100完成two 100完成two 100完成two 100完成Synch 结束!17、阅读以下程序,并填空。import _ ;class FileType public st
17、atic void main(String args) _; try FileReader fis = new_(args0); BufferedReader reader = new BufferedReader( ); String s; while(s=()!=_) +(i+)+: + s); (); (); catch (IOException e) catch (_ e1) 缺少命令行参数!”); 程序填空:.*;int i;FileReaderfisnullArrayIndexOutOfBoundsException18、阅读以下程序:public class Sum public
18、 static void main(String args) double sum = : for (int i=1; i=100; i+) sum += i*i; sum=+sum); 该程序的功能是:求出sum的值为1到100的平方和。19、阅读以下程序:class Example public static void main(String args) int a = new int33; a00=1; a11=1; a22=1; 数组a:); for (int i=0; i ; i+) for(int j=0; j ai.length; j+) + ); 该程序的输出结果是:1 0 0
19、0 1 00 0 120、阅读以下程序:public class Test2 static boolean foo(char c) return true; public static void main(String args) int i = 0: for(foo(A); foo(B) & (i2); foo(C) i+; foo(D); 此程序的输出结果是:ABDCBDCB21、阅读以下程序,并填空。import _;import class OvalDrawer extends Frame implements Runnable private Color colors= , , ;
20、private Color color; private int x=l0,y=10,width=10,height=10; public OvalDrawer(String title) super(title); _; ;setSize(300,300);new Thread(this).start();repaint();(x,y,width,height);22、阅读以下程序:public class Sum public static void main(String args) double sum = ; for (int i=1; i=100; i+) sum += / (do
21、uble)i; sum=+sum); 此程序完成的功能是:求解sum=1+1/2+1/3+.+1/100的值并打印输出。23、阅读以下程序:import .*;import class Applet1 extends Applet public void paint(Graphics g) (30,5,100,45); (30,50,50,20); (30,80,50,40); (They are figures! ,30,150); 此程序完成的功能是:在Applet界面中显示一些由直线、矩形框、椭圆框和文字组成的图形。24、阅读以下程序:import .*;public class Tes
22、t public static void main(String args) int i; int a=11,22,33,44,55,66,77,88,99; for(i=0; i = 2; i+) + a + ); 此程序的输出结果是:110 110 110 110 11025、阅读程序并填空import .*;import .*;public class DrawStringDemo _ Applet private Font afont = _Font(Helvetica,18); public void init() _; public void paint(Graphics g) ;
23、 _(afont); _(This is a test,10,40); 程序填空:extends new setBackground setFont drawString26、阅读以下程序public class Test( public static void main(String args) sqrt=%f, ); 此程序的输出是:sqrt=27、阅读以下程序public class SumTest public static void main(String args) double sum = ; for(int i=1; i 0 ) y = 2 * x; else if( x =
24、0) y = 2 + (x); else y = x * x + 1; y= + y); 此程序完成的功能是:从键盘输入一个数x,根据x的值求出相应的y值。 2*x x0y= 2 + cos(x) x=0 x2+1 x029、阅读以下程序,完成填空,使其完整。import _;class Rectangle public static void main(String args) _w,l,S,s; double()w*l(w+l)*230、阅读以下程序:public class Sum public static void main(String args) double sum = ; for(int i = 1; i = 100; i+) sum += i*i*i; + sum); 此程序完成的功能是:计算并输出1到100的立方和sum值。31、阅读以下程序