付费下载
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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)请写出该程序的功能:该程序使用字符缓冲输入流从键盘输入 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 += ai; 请写出该程序的输出结果: s=2603、阅读以下程序:import jav
3、a.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<data_arr.length; i+)randf.writelnt(data_arri); randf.writeUTF("Good morning
4、!"); ' for(int i=data_arr.length-l; i>=0; i=i-2) randf.seek(i*4);System,out.print(" "+randf.readInt(); randf.seek(40);randf.close(); catch (IOException e) 该程序的输出结果是: 99 65 1 23 66 Good morning!4、阅读以下程序并填空。class extends Exception H,String mymsg=" 我自己定义的异常!double mynum = 2.0
5、;MyException () super("首字母不能为 A! ") ; MyException (String msg) / 调用父类构造方法 , 参数为 msgpublic double mymethod() return Math.sqrt(mynum); class ExceptionTest public static void main(String args) try if ( argsO.charAt(O)= 'A') MyException e = new MyException();e.displayme();第一个字符不应是 B! &
6、quot;) ; ) Systemout println("*in try*"); ; / 抛出异常 e else if(argsO.charAt(O)= 'B') throw new MyException (" catch ( aaa.displayme(); catch( 程序填空:MyException super(msg) throw eMyException aaaArrayIndexOutOfBoundsException5、阅读以下程序 import java.io.*;public class Test public static
7、 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 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) su
8、per(aa,bb,cc); a = aa + bb + cc;void show() 请写出该程序的运行结果: a=60 b=20 c=306、阅读以下程序 import java.io.*; public class abc public static void main(String args) String sl = "Hello!"String s2 = new String("World!");请写出该程序的运行结果:Hello!World!7、阅读以下程序import java.io.*;public class Class1 public
9、 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<a.length; i+)if( ai< min) min = ai;if( ai> max) max = ai;请写出该程序完成的功能:在数组中查找并输出最大值和最小值。8、阅读以下程序 import java.awt.*;public class DrawMylmage extends Applet Image myImage; /定义一个图像类 Ima
10、ge 的对象 myImagepublic void init()myImage= getImage(getDocumentBase(),"pica.jpg");public void paint(Graphics g) g.drawImage(myImage,0,0,this);pica.jpg ”的图像。 请写出该程序的功能: 在 Applet 界面中显示当前文件夹下名为“Applet 9、阅读以下程序并填空。 import java.awt.*; import java.applet.*; import .*; public class Mypicture Image
11、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 public static void main( String args) double sum
12、 = 0.0 ;for ( int i = 1; i<= 100; i + )sum += i;,该程序完成的功能是:求 sum=1+2+3+.+100 的和。11、阅读以下程序:class SuperClass int a,b;SuperClass(int x,int y) a=x; b=y; class SubClass extends SuperClass int c;SubClass(int aa,int bb,int cc) super(aa,bb);c=cc;voidshow() class SubSubClass extends SubClass int a;SubSubC
13、lass(int aa,int bb,int cc) super(aa,bb,cc); a=aa+bb+cc;void show()class test public static void main(String args) SuperClass p=new SubSubClass(10,20,30); p.show(); 该程序的输出结果是: a=60 b=20 c=3012、阅读以下程序:import java.io.*;publiic class Test public static void main(String args) AB s = new AB("Hello!&q
14、uot;,"I love Java.");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(Stringo args) int ch;FileInputStream fin; fout;try fin = new
15、 FileInputStream(args0); fout = new FileOutputStream(ch = fin.read();while(ch!=-1) ch = fin.read();fin.close(); fout.close(); catch ( e1) System.exit(0); catch (FileNotFoundException e3) catch (IOException e2) 程序填空:import java.io.*;FileOutputStreamargs0fout.write(ch);ArrayIndexOutOfBoundsException14
16、、阅读以下程序import java.io.*;public class Reverse public static void main(String args) int i,n=10;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
17、-)请写出此程序功能:程序运行时从键盘输入 10 个整数,然后倒序输出。15、阅读以下程序 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; 请写出此程序的输出结果: s=18016、阅读以下程序(提示:注意同步) class Onesynchronized void
18、 display(int num) try Thread.sleep(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); t.start();public void run() one.display(number);public class Synch public
19、 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); 此程序的输出结果是: two 100 完成 two 100 完成 two 100 完成 two 100 完成Synch 结束!17、阅读以下程序,并填空。 import ;class
20、FileTypepublic static void main(String args)try FileReader fis = new(args0);BufferedReader reader = new BufferedReader( ); String s ; while(s=reader.readLine()!=_ fis.close(); reader.close(); catch (IOException e) catch ( e1) “缺少命令行参数! ” ); 程序填空: java.io.*;int i;FileReaderfisnullArrayIndexOutOfBound
21、sException18、阅读以下程序: public class Sum public static void main(String args) double sum = 0.0 : for (int i=1; i<=100; i+) sum += i*i ;该程序的功能是:求出sum的值为1到100的平方和。19 、阅读以下程序: class Example 该程序的输出结果是:1 00 10 020、public static void main(String args) int a = new int33; a00=1; a11=1; a22=1; for (int i=0;
22、i < a.length; i+) for(int j=0; j < ai.length; j+) 001阅读以下程序: public class Test2static boolean foo(char c)return true;public static void main(String args)int i = 0 :for(foo('A'); foo('B') && (i<2); foo('C') i+; foo('D'); 此程序的输出结果是: "ABDCBDCB"
23、 21、阅读以下程序,并填空。 import ;public class OvalDrawer extends Frame implements Runnable private Color colors= Color.RED,Color.BLACK,Color.BLUE, Color.GREEN,Color.DARK_GRAY ;private Color color;private int x=l0,y=10,width=10,height=10;public OvalDrawer(String title)super(title); / 设置窗口大小为 300*300setVisible
24、(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(int)(Math.random()*(colors.length-1); ; / 刷新窗口内容 try Thread.sleep(400); catch(InterruptedException e) throw new Run
25、timeException(e);public void paint(Graphics g)g.setColor(color); / 画椭圆public static void main(String args) new OvaIDrawer("hello");程序填空: java.awt.*;setSize(300,300);new Thread(this).start(); repaint();g.drawOval(x,y,width,height); 22、阅读以下程序: public class Sum public static void main(String
26、args) double sum = 0.0 ; for (int i=1; i<=100; i+) sum += 1.0 / (double)i;此程序完成的功能是:求解 sum=1+1/2+1/3+.+1/100 的值并打印输出。23、阅读以下程序:import java.awt.*;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.drawStrin
27、g("They are figures! ",30,150); 此程序完成的功能是: 在 Applet 界面中显示一些由直线、矩形框、椭圆框和文字组成的图形。24、阅读以下程序: import java.io.*;public class 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+) 此程序的输出结果是: 110 110 110 110 11025、阅读程序并填空 import java.aw
28、t.*; import java.applet.*; Applet Font("Helvetica",Font.BOLD,18);public class DrawStringDemo private Font afont = public void init() (Color.black); public void paint(Graphics g) g.setColor(Color.green); (afont); ("This is a test",10,40);setFont drawString 程序填空: extends new setBac
29、kground 26、阅读以下程序 public class Test(public static void main(String args) 此程序的输出是: sqrt(2.0)=1.414214 27、阅读以下程序 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);此程序完成的功能是:从命令行输入若干个数,求这若干个数的和并输出结果。 28、阅读以下
30、程序 class IfTest public static void main(String args)double y,x;Scanner keyin = new Scanner(System.in); ”请输入 x 的值:”);x = keyin.nextDouble();if ( x > 0 ) y = 2 * x;else if( x = 0) y = 2 + Math.cos(x);else y = x * x + 1; 此程序完成的功能是: 从键盘输入一个数X,根据x的值求出相应的y值。2*xx>0y= 2 + cos(x) x=0 x2+1x<029、阅读以下程序,完成填空,使其完整。 import ;class Rectangle public static void main(String args) w,l,S,s; / 定义变量 Scanner keyin = new Scanner
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2027届武汉市武昌区数学三上期末检测模拟试题含解析
- 会宁县2027届四年级数学第一学期期末统考试题含解析
- 2027届四川省成都市大邑县四年级数学第一学期期末考试试题含解析
- 济宁市市中区2027届数学四年级第一学期期末调研模拟试题含解析
- 攀枝花市盐边县2027届数学四年级第一学期期末综合测试模拟试题含解析
- 《影视视听语言教程(第2版)》全套教学课件
- 一年级数学计算题专项练习1000题汇编
- 2026年郑州市高考仿真卷生物试题含解析
- 2026全球新能源科技产业市场势态监测及产业链优化与商业价值研究报告
- 2026清洁能源行业市场深度调研及发展前景与趋势预测研究报告
- 《2025年宁夏社区工作者招聘考试高频考点试题解析》
- 村级报账员业务培训课件
- 人工智能赋能乡村治理的实践逻辑、现实困境与优化路径
- 2026年区分观点与事实基础练习含答案
- 光模块行业2026年市场需求与技术演进趋势分析
- 服装质检培训课件模板
- 小学高年级学生习作修改的现状、困境与突破路径研究
- 2026公务员考试时事政治题与答案
- 全国内部审计数智化转型发展研究报告
- 数字孪生技术在土木工程中的应用与施工全流程精准管控研究毕业论文答辩汇报
- 糖尿病急性并发症处理措施培训
评论
0/150
提交评论