湖南大学2012年JAVA课程考试试卷

上传人:枫** 文档编号:563201242 上传时间:2023-11-10 格式:DOC 页数:5 大小:23.50KB
返回 下载 相关 举报
湖南大学2012年JAVA课程考试试卷_第1页
第1页 / 共5页
湖南大学2012年JAVA课程考试试卷_第2页
第2页 / 共5页
湖南大学2012年JAVA课程考试试卷_第3页
第3页 / 共5页
湖南大学2012年JAVA课程考试试卷_第4页
第4页 / 共5页
湖南大学2012年JAVA课程考试试卷_第5页
第5页 / 共5页
亲,该文档总共5页,全部预览完了,如果喜欢就下载吧!
资源描述

《湖南大学2012年JAVA课程考试试卷》由会员分享,可在线阅读,更多相关《湖南大学2012年JAVA课程考试试卷(5页珍藏版)》请在金锄头文库上搜索。

1、2012-2013第一学期Java 程序设计 专业班级:_学号:_ 姓名:_ 分数:_第一题、 写出下面程序的运行结果.(10分)public class abc public static void main(String args ) AB s = new AB(Hello!,I love JAVA.); class AB String s1; String s2; AB( String str1 , String str2 ) s1 = str1; s2 = str2; public String toString( ) return s1+s2;第二题、编程题(90分)1. 创建一个桌

2、子Table类,该类中有桌子名称,重量,桌面宽度,长度及桌子高度属性。其中有:构造函数初始化所有数据成员;Area() :计算桌面的面积;Display(): 在屏幕上输出所有数据成员的值;ChangeWeight(int ):改变桌子重量的函数。在main()中实现创建一个桌子对象,计算桌面的面积,改变桌子重量,并在屏幕上输出所有桌子数据成员的值。(15分)2. 用main()创建一个类,令其掷出try块内的Exception类的一个对象。为Exception的构建器赋予一个字串参数。在catch从句内捕获例外,并打印出字串参数。添加一个finally从句,并打印一条消息,证明自己真正到达那

3、里。(15分)class TestTest() throws Exceptionthrow new Exception(自定义异常!);public class ExceptionTest public static void main(String args)tryTest test=new Test();catch(Exception e)finally3. 创建一个double 数组,随即产生数组元素的数值。然后将其排序,打印排序结果。查找第5个元素,打印其值。(10分)package sort;public class sort public static void main(Stri

4、ng args)double db=new double10;for(int i=0;i10;i+)dbi=Math.random();for(int i=0;i10;i+)for(int i=0;ii;j-)if(dbjdbj-1)double t=dbj;dbj=dbj-1;dbj-1=t;for(int i=0;i10;i+)4. 用HashMap存放一组星期一到星期日的组对,1-7对应Mon-Sun.。(15分) a.打印这组数据 b.分别打印1-7 和Mon-Sunc.查找3对应的英文星期package hashmap;public class hashmap public stat

5、ic void main(String args)HashMap map=new HashMap();map.put(1, mon);map.put(2,tue);map.put(3,wend);for(int i=1;i=3;i+)5. 编写两个线程:一个线程向数组中存数据,一个线程向数组中取数据。练习如何实现线程的同步。(15分)class WriteThread extends Threadpublic ArrayList List=new ArrayList();public WriteThread(ArrayList a)List=a;public void run()synchro

6、nized (this) for(int i=0;i10;i+)List.add(i);trysleep(500);catch(Exception e)return;class ReadThread extends Threadpublic ArrayList List=new ArrayList();public ReadThread(ArrayList a)List=a;public void run()synchronized (this) for(int i=0;i10;i+)trysleep(500);catch(Exception e)return;public class RWt

7、hread public static ArrayList List=new ArrayList();public static void main(String args)WriteThread writeThread=new WriteThread(List);ReadThread readThread=new ReadThread(List);writeThread.start();readThread.start();6. 从标准设备中输入若干行英文句子,直到输入bye结束,将这些字符串写入文件。(10分)/通过下面这个方法可以实现标准输入和输出,使用scanner类package s

8、tandarinput;public class standarinput public static void main(String args)Scanner scanner=new Scanner(System.in);String tempString=scanner.next();int a=scanner.nextInt();/通过BufferedReader进行标准输入以及输出到文本当中public class BufferReader public static void main(String args) throws IOExceptionFile fileName=new

9、 File(F:/abc.txt);BufferedReader br=new BufferedReader(new InputStreamReader(System.in);BufferedWriter bw=new BufferedWriter(new FileWriter(fileName,true);while(true)String temp=br.readLine();bw.write(temp+rn);if(temp.equals(bye)break;bw.flush();bw.close();br.close();7. 打印出所有的“水仙花数”,所谓的“水仙花数”是指一个三位数,其各位数字的立方和等于其本身。例如:153是个“水仙花数”,因为153= (10分)package waterflowers;public class waterflowers public static int judge(int x)int a,b,c,t=x;a=x%10;x/=10;b=x%10;x/=10;c=x%10;if(a*a*a+b*b*b+c*c*c=t)return 1;else return 0;public static void main(String args)for(int i=100;i1000;i+)if(judge(i)=1)

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 高等教育 > 习题/试题

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号