已阅读5页,还剩2页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
JAVA程序设计复习提纲1.下面的程序通过方法调用从包含7个学号的数组中随机抽取一个学号并输出显示,请将下面的程序填写完整。public class Ex1 public String getXh()String xhs = 201001,201002,201003,201004,201005,201006,201007;int index = Math.random()*6 ; /Math.random()生成06之间的随机数。return xhsindex;public static void main(String args)System.out.println(随机抽取的学号为:+ );2. 下面的程序定义了一个线程TimeThread,该线程每隔1秒钟输出显示一次当前系统时间,在main方法中使用TimeThread类创建3个新线程,并启动这些线程,请将下面的程序填写完整。import java.util.*;class TimeThread implements public void run() while (true) Date currentTime = new Date(); try ; / 休眠1秒钟 catch (Exception e) System.out.println(e.toString();System.out.println(Thread.currentThread().getName()+: +currentTime); public class Ex2 public static void main(String args) String names=first,second,third; TimeThread myThread = new TimeThread(); for(int i=0;i3;i+) Thread threadObj= new Thread(myThread,namesi); ; /启动线程 3.下面的程序对“百鸡百钱”问题进行了求解,公鸡每只3元,母鸡每只5元,小鸡3只1元,用100元钱买100只鸡,公鸡、母鸡、小鸡应各买多少4. 下面的程序使用BufferedWriter类在D:Hello.txt文件中写入10万个数并输出所用的时间,请将程序填写完整。import java.io.*;public class Ex4 public static void main(String args) throws IOExceptionlong t = System.currentTimeMillis();BufferedWriter fw =new BufferedWriter( “D:Hello.txt” );for (int i=1;i=100000;i+) fw.write ( i + n);fw.close();t=System.currentTimeMillis()-t;System.out.println(Time elapsed: +t +ms);new FileWriter(“d:hello.txt”)fw.write5.根据程序注释提示将下面的程序填写完整。class StringExample public static void main(String args) String s1=new String(2012); String s2=new String(100.50); int x = ; / 将s1转换为int类型 double y = ; / 将s2转换为double类型 double z = x + y; String s3 = ; /将z转换为字符串 StringBuffer sbr = new StringBuffer(Thingking); String s4 = new String(in Java); ; /将s4连接在sbr的后面System.out.println(sbr.toString(); /显示为 Thingking in Java 1. 写出下面程序的运行结果。public class Exam4 String str=new String(aust); char ch = s,s,j;public static void main(String args) Exam4 ex = new Exam4(); ex.change(ex.str,ex.ch); System.out.println(ex.str+ and); System.out.println(ex.ch); public void change(String str,char ch) str = jsjxy; ch0 = j; 运行结果:2. 写出下面程序的运行结果。public class ExceptionExample public static void main(String args)tryString str = new String(abcdefg);char mychars = str.toCharArray();for(int i=0;i=mychars.length;i+)System.out.print(mycharsi);if(i=mychars.length-1)System.out.println();catch(ArrayIndexOutOfBoundsException e)System.out.println(ArrayIndexOutOfBounds!);catch(Exception e)System.out.println(Exception!);finallySystem.out.println(Program End!);运行结果:3. 写出下面程序的运行结果。 import java.util.*; public class CollectionTester public static void main(String args) Vector teamList = new Vector(); teamList.add(Zhang Wei);teamList.add(Liu Hong); teamList.add(Yu Hongshu); teamList.set(2,Liu Na); teamList.remove(0); teamList.remove(0); System.out.println(teamList.get(0); Hashtable ht = new Hashtable(); ht.put(key,Zhang Wei); ht.put(key,Liu Hong); Iterator its = ht.values().iterator(); while(its.hasNext() System.out.println(its.next(); 运行结果:Liu NaLiu Hong4. 写出下面程序的运行结果。 import java.util.*; public class ArrayTester public static void main(String args) int arrays1 = 1,3,5; int arrays2 = 2,4,6; int arrays3 = new int3; arrays2=arrays3; for(int i=0;iarrays3.length;i+) arrays3i=arrays1i; for(int i=0;iarrays2.length;i+) System.out.println(arrays2i); 运行结果: . 写出下面程序的运行结果。public class Figure public int xPosition,yPosition;public void draw()System.out.println(drawing Figure);public class Rectangle extends Figurepublic void draw()System.out.println(drawing Rectangle);public class Circle extends Figurepublic void draw()System.out.println(drawing Circle); public class Testerpublic static void main(String args)Figure figures = new Figure3;figures0=new Figure();figures1=new Rectangle();figures2=new Circle();for(int i=0;ifigures.length;i+)figuresi.draw();运行结果: drawing Figuredrawing Rectangledrawing Circle1. 水仙花数是指这样的三位数,其个位、十位和百位三个数的平方和等于这个三位数本身,请编写程序打印输出所有(100999之间)的水仙花数。2. 定义一个包括10个元素一维整型数组,通过从键盘输入的10个整数对数组进行初始化,对数组中的元素按小到大排序后在屏幕上显示,求出该数组中元素的最小值、最大值以及平均值并在屏幕上显示输出。import java.util.Scanner;import java.util.Arrays;public class Testpublic static void main(String args) int x = new int10;double sum =0;Scanner scr = new Scanner(System.in);for(int i=0;ix.length;i+)xi= scr.nextInt();Arrays.sort(x);for(int i=0;ix.length;i+)sum += xi;System.out.println(Max=+xx.length-1);System.out.println(Min=+x0);System.out.println(Average=+sum/x.length);3. 编写一个应用程序创建两个线程,一个线程打印输出11000之间所有3的倍数,另外一个线程打印输出10002000之间所有5的倍数,并在主程序中启动这两个线程。public class three extends Thread public three (String n) super(n); public void run() for(int i=1;i=1000;i+)if(i % 3 =0)System.out.println(i+); public class five extends Threadpublic five (String m)super(m);public void run() for(int i=1000;i=2000;i+)if(i % 5 =0)System.out.println(i+); public class threadexample public static void main(String args)three x = new three(three);five y = new five(five);x.start();y.start();4. 编写描述一个圆的类Circle,包含的属性有:圆点x坐标,圆点的y坐标,半径,包含的方法有:每个属性的set的get方法分别用于赋值,取值操作,另外编写一个求面积的area方法/调用Math.PI 返回double类型的PI5,编写上题的测试类,调用set方法,分别设置x坐标,y坐标,半径,并调用area方法输出圆的面积。public class Circleprivate double xpoint;private double ypoint;private double radius;public double getXpoint()return this.xpoint;public double getYpoint()return this.ypoint;public double getRadius()return this.radius;public void setX
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 外研版小学四年级英语下册课时3 Unit1 Peopleatwork教学设计
- 结直肠癌围手术期的护理
- 《鸟和哺乳动物》教学设计-2026-2027学年人教鄂教版(新教材)小学科学四年级上册
- 2026下半年小学教师资格证考试综合素质考前押题试卷及解析
- 检验科第一季度医院感染管理工作总结(2篇)
- 骨质疏松性椎体压缩骨折诊疗专家共识解读 课件
- 试管婴儿健康宣教方案
- 住院保胎孕妇宣教
- 2026及未来5年中国塑料旅行瓶数据监测研究报告
- 城市消防安全综合治理
- 2025架空输电线路使用多旋翼无人机三维激光建模及自动巡检全流程技术规范
- T/CMEAS 010-2023标准化病人(SP)医学教育项目建设与应用指南
- 床旁徒手盲插鼻空肠管流程
- 工业品销售培训
- 吉利汽车营销策略分析
- 宿管员服务礼仪培训
- 护理高质量发展措施
- 码头安全生产管理制度
- 2011桂林奥林匹克花园项目发展战略及2012年推广报告2
- 公司售电业务管理制度
- 无锡旅游景点攻略惠山古镇
评论
0/150
提交评论