![Java复习题阅读程序题软件_第1页](http://file3.renrendoc.com/fileroot_temp3/2022-2/15/4741c140-3889-48d7-9f09-cc0e4e9dd913/4741c140-3889-48d7-9f09-cc0e4e9dd9131.gif)
![Java复习题阅读程序题软件_第2页](http://file3.renrendoc.com/fileroot_temp3/2022-2/15/4741c140-3889-48d7-9f09-cc0e4e9dd913/4741c140-3889-48d7-9f09-cc0e4e9dd9132.gif)
![Java复习题阅读程序题软件_第3页](http://file3.renrendoc.com/fileroot_temp3/2022-2/15/4741c140-3889-48d7-9f09-cc0e4e9dd913/4741c140-3889-48d7-9f09-cc0e4e9dd9133.gif)
![Java复习题阅读程序题软件_第4页](http://file3.renrendoc.com/fileroot_temp3/2022-2/15/4741c140-3889-48d7-9f09-cc0e4e9dd913/4741c140-3889-48d7-9f09-cc0e4e9dd9134.gif)
![Java复习题阅读程序题软件_第5页](http://file3.renrendoc.com/fileroot_temp3/2022-2/15/4741c140-3889-48d7-9f09-cc0e4e9dd913/4741c140-3889-48d7-9f09-cc0e4e9dd9135.gif)
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、word 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
2、 >= 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 ; i
3、+ )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"
4、); for (int i=0; i<data_arr.length; i+) randf.writelnt(data_arri); randf.writeUTF("Good morning!"); ' for(int i=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(); catc
5、h (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("首字母不能为A! "); MyException (String msg)_ /调用父类构造方法,参数为 msg public v
6、oid 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.mymethod();e.displayme();Systemoutpr
7、intln("*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(); n("" + aaa.mymethod(); catch( _ ) System.out.println("命令行参数个数
8、错!"); 程序填空: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
9、 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、阅读
10、以下程序import java.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
11、;int a = 12,67,8,98,23,56,124,55,99,100);max= min= a0;for(i=1; i<a.length; i+)if( ai< min) min = ai;if( ai> max) max = ai;System.out.println( max + " " + min);System.out.println(); 请写出该程序完成的功能:在数组中查找并输出最大值和最小值。8、阅读以下程序import java.awt.*;import java.applet.Applet;public class DrawMy
12、lmage extends Applet Image myImage; /定义一个图像类Image的对象myImage public void init()myImage= 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 .
13、*;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 repaint10、阅读以下程序:public class Sum pub
14、lic static void main( String args) double sum = 0.0 ; for ( int i = 1; i<= 100; i + ) sum += i;, System.out.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 + "
15、;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 +"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;
16、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、阅读以下程序:import java.io.*;publiic class Test public static void main(String args) AB s = ne
17、w 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、阅读以下程序,并填空。import _class MyCopy public static void main(St
18、ringo 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 mycopy源文件名目标文件名");System.exit(0); catch (FileNotFou
19、ndException 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(String args) int i,n=10
20、;int a = new int10;for(i=0; i<n; i+)try BufferedReader br= new BufferedReader(new InputStreamReader(System.in);ai=Integer.parseInt(br.readLine(); /输入一个整数 catch (IOException e) ;for (i = n-1; i >= 0; i-)System.out.print(ai+" ");System.out.println(); 请写出此程序功能:程序运行时从键盘输入10个整数,然后倒序输出。15、
21、阅读以下程序import java.io.* ;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 < a.length; i+ )if(ai % 3 = 0) s += ai;System.out.println("s=" + s);请写出此程序的输出结果:s=18016、阅读以下程序提示:注意同步class One synchronized void displa
22、y(int num) System.out.println("two " + num);try Thread.sleep(1000); catch (InterruptedException e) System.out.println(中断);System.out.println(完成); 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);t.star
23、t(); public void run()one.display(number);public class Synch public static void main(String args) 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);in();s2.t.join();s3.t.join
24、();s4.t.join();System.out.println("Synch结束!"); 此程序的输出结果是:two 100完成two 100完成two 100完成two 100完成Synch 结束!17、阅读以下程序,并填空。import _ ;class FileTypepublic static void main(String args)_; try FileReader fis = new_(args0);BufferedReader reader = new BufferedReader( );String s;while(s=reader.readLine
25、()!=_) System.out.println(" "+(i+)+":" + s);fis.close();reader.close(); catch (IOException e) System.out.println(e); catch (_ e1) System.out.println(“缺少命令行参数!); 程序填空:java.io.*;int i;FileReaderfisnullArrayIndexOutOfBoundsException18、阅读以下程序:public class Sum public static void main(
26、String args) double sum = 0.0:for (int i=1; i<=100; i+)sum += i*i;System.out.println( "sum="+sum); 该程序的功能是:求出sum的值为1到100的平方和。19、阅读以下程序:class Example public static void main(String args) int a = new int33;a00=1; a11=1; a22=1;System.out.println("数组a:");for (int i=0; i < a.len
27、gth; i+) for(int j=0; j < ai.length; j+)System.out.print(aij + " ");System.out.println(); 该程序的输出结果是:1 0 00 1 00 0 120、阅读以下程序:public class Test2static boolean foo(char c)System.out.print(c);return true; public static void main(String args)int i = 0:for(foo('A'); foo('B')
28、&& (i<2); foo('C')i+;foo('D'); 此程序的输出结果是:"ABDCBDCB"21、阅读以下程序,并填空。import _;import java.awt.event.*;public class OvalDrawer extends Frame implements Runnable private Color colors= Color.RED,Color.BLACK,Color.BLUE,Color.GREEN,Color.DARK_GRAY ; private Color color; p
29、rivate int x=l0,y=10,width=10,height=10; public OvalDrawer(String title)super(title);_; /设置窗口大小为300*300setVisible(true);_; /创立线程并启动 public void run() while(true) x = (int)(Math.random0*300);y = (int)(Math.random0*300);width = (int)(Math.random()*100);height = (int)(Math.random()*100);color = colors(
30、int)(Math.random()*(colors.length-1);_; /刷新窗口内容try Thread.sleep(400); catch(InterruptedException e) throw new RuntimeException(e); public void paint(Graphics g)g.setColor(color);_; /画椭圆 public static void main(String args) new OvaIDrawer("hello"); 程序填空:java.awt.*;setSize(300,300);new Threa
31、d(this).start();repaint();g.drawOval(x,y,width,height);22、阅读以下程序:public class Sum public static void main(String args) double sum = 0.0;for (int i=1; i<=100; i+) sum += 1.0 / (double)i;System.out.println("sum="+sum); 此程序完成的功能是:求解sum=1+1/2+1/3+.+1/100的值并打印输出。23、阅读以下程序:import java.awt.*;i
32、mport java.applet.Applet;public class Applet1 extends Applet public void paint(Graphics g) g.drawLine(30,5,100,45);g.drawRect(30,50,50,20);g.drawOval(30,80,50,40);g.drawString("They are figures! ",30,150); 此程序完成的功能是:在Applet界面中显示一些由直线、矩形框、椭圆框和文字组成的图形。24、阅读以下程序:import java.io.*;public class
33、Test public static void main(String args) int i;int a=11,22,33,44,55,66,77,88,99;for(i=0; i <= a.length/2; i+)System.out.print(ail + aa.length-i-1 + " ");System.out.println(); 此程序的输出结果是:110 110 110 110 11025、阅读程序并填空import java.awt.*;import java.applet.*;public class DrawStringDemo _ App
34、let private Font afont = _Font("Helvetica",Font.BOLD,18); public void init() _(Color.black); public void paint(Graphics g) g.setColor(Color.green);_(afont);_("This is a test",10,40); 程序填空:extends new setBackground setFont drawString26、阅读以下程序public class Test( public static void m
35、ain(String args)System.out.printf("sqrt(2.0)=%f", Math.sqrt(2.0); 此程序的输出是:sqrt(2.0)=1.41421427、阅读以下程序public class SumTest public static void main(String args) double sum = 0.0;for(int i=1; i <= args.length; i+)sum += Double.parseDouble(argsi);System.out.println("sum=" + sum);
36、此程序完成的功能是:从命令行输入假设干个数,求这假设干个数的和并输出结果。28、阅读以下程序import java.util.Scanner;class IfTest public static void main(String args)double y,x;Scanner keyin = new Scanner(System.in);System.out.print(请输入x的值:);x = keyin.nextDouble();if ( x > 0 ) y = 2 * x;else if( x = 0) y = 2 + Math.cos(x);else y = x * x + 1;
37、 System.out.println("y=" + y); 此程序完成的功能是:从键盘输入一个数x,根据x的值求出相应的y值。 2*x x>0y= 2 + cos(x) x=0 x2+1 x<029、阅读以下程序,完成填空,使其完整。import _;class Rectangle public static void main(String args) _w,l,S,s; /定义变量Scanner keyin = new Scanner(System.in);System.out.print(请输入长方形的长:);l = keyin.nextDouble();System.out.print(请输入长方形的宽:);w = _ ; /输入宽S = _ ; /计算面积并保存在S中s = _ ; /计算周长并保存在s中System.out.println("此长方形的面积:"+ S +"n此长方形的周长:" +s); 程序填空:java
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 【正版授权】 IEC 62576:2009 EN-FR Electric double-layer capacitors for use in hybrid electric vehicles - Test methods for electrical characteristics
- 【正版授权】 IEC 62541-3:2010 EN-FR OPC unified architecture - Part 3: Address Space Model
- 数据库技术与应用 课件全套 李红日 项目1-10学生成绩管理系统数据库的设计-学生成绩管理系统数据安全管理
- 城市更新投资合同
- 生产效率提升方案及实施进度追踪三篇
- 客户满意度调研和反馈的月度计划三篇
- 薪资福利专员聘用合同
- 2023年学生课外教育服务项目成效分析报告
- 落实学生创造力教育与实践的工作计划
- 美容整形协议
- 证券投资分析PPT
- 五星级酒店功能区与面积配置推荐保存
- 气管插管配合操作流程
- 血透室工作流程
- 国际快递发票(样板)
- 田蕴章每日一字楷行草三体示范字帖_图文
- modtran操作步骤及输入参数说明
- 城市管理学期末复习题
- 糕点切片机毕业设计
- 工程结算单(样本)
- 杨思卓探索卓越领导力修炼之道
评论
0/150
提交评论