java程序设计模拟题.doc

上传人:PIYPING 文档编号:11502024 上传时间:2021-08-10 格式:DOC 页数:7 大小:75.50KB
返回 下载 相关 举报
java程序设计模拟题.doc_第1页
第1页 / 共7页
java程序设计模拟题.doc_第2页
第2页 / 共7页
java程序设计模拟题.doc_第3页
第3页 / 共7页
java程序设计模拟题.doc_第4页
第4页 / 共7页
java程序设计模拟题.doc_第5页
第5页 / 共7页
点击查看更多>>
资源描述

《java程序设计模拟题.doc》由会员分享,可在线阅读,更多相关《java程序设计模拟题.doc(7页珍藏版)》请在三一文库上搜索。

1、Java程序设计模拟题一、 填空题1.在使用interface声明一个接口时,只可以使用 修饰符修饰该接口。2. 方法是一种仅有方法声明,没有具体方法体的方法。3.Java中的Applet小程序需要嵌套在 文件中才可以执行。4.如果一个Java Applet程序文件中定义有3个类,则使用Sun公司的JDK编译器 编译该源程序文件将产生 个文件名与类名相同而扩展名为 的字节码文件。5.当一个类实现Runnable接口时,必须要实现的方法是 。二、 单项选择题1.下面关于Java application与applet的说法中,正确的是( )。A)都包含有main方法 B)都通过浏览器运行C)都通过

2、“javac”编译 D)都嵌入在HTML中运行2. Frame缺省使用的布局编辑策略是( )。A)FlowLayout B)BorderLayout C)GridLayout D)CardLayout3以下关于Java的继承性叙述正确的是( )。A)在Java中类只允许单一继承B)在Java中一个类只能实现一个接口C)在Java中一个类不能同时继承一个类和实现一个接口D)在Java中接口只允许单一继承4下面程序运行结果是( )。( ) public class Equivalencepublic static void main(String args) Integer n1=new Inte

3、ger(47); Integer n2=new Integer(47); System.out.println(n1=n2);System.out.println(n1!=n2); A) false trueB)true falseC) false falseD)ture true5在Java中,对象在何种状态下会被回收?( )。A)当没有引用变量再指向该对象时B)当对象关系的引用变量消失时C)当没有任何程序再访问一个对象或对象的成员变量时D) 当对象的所有成员函数都执行一遍以后6如果catch块中包括多个异常类,这些异常类的匹配原则是什么?( )A)接try块中程序执行的顺序,寻找最通用的异

4、常类B)接try块中程序执行的顺序,寻找能够最精确匹配的类C)接catch块中异常类的排列顺序,寻找第一个能够匹配(也就是抛出的异常对象属于catch块的异常类,或是catch块中异常类的)D)在catch块中寻找能够最精确匹配的类7假设Foo类有如下定义,设f是Foo类的一个实例,下列语句调用哪个是错误的?( )public class Fooint i;static String s;void imethod() static void smethod() A)Foo.imethod();B)f.imethod();C)System.out.println(f.i);D)Foo.smeth

5、od()8下列说法不正确的是( )A)IOException必须被捕获或抛出 B)java语言会自动初始化变量的值 C)java语言不允许同时继承一个类并实现一个接口 D)java语言会自动回收内存中的垃圾9package语句正确的是 ( )A)必须在程序开头 B)不一定在程序开头 C)可以在import之后 D)包名可以以数字开头 10关于接口跟抽象类正确的是( )A)接口能够创建对象B)抽象类能够创建对象C)接口中不能定义变量,都是常量D)接口中可以有private 方法三、 程序阅读题1写出以下程序的功能。import java.io.*;public class TestFile pu

6、blic static void main(String args) throws Exception BufferedReader br=new BufferedReader(new InputStreamReader(System.in); BufferedWriter bw = new BufferedWriter(new FileWriter(“input.txt); String s; while (true) System.out.print(请输入一个字符串: ); System.out.flush(); s=br.readLine(); if (s.length()=0) br

7、eak; bw.write(s); bw.newLine(); bw.close(); 2、若文件test.dat不存在,则试图编译并运行以下程序时会发生什么情况?import java.io.*;class TestIOpublic static void main(String args)tryRandomAccessFile raf=new RandomAccessFile(test.dat,r);int i=raf.readInt();catch(IOException e)System.out.println(IO Exception); 3、阅读以下程序,若输入:12345写出以下

8、程序的运行结果。 import java.io.* ; public class Test_3 public static void main(String args ) int a = new int5; for (int i = 0 ; i a.length ; i+ ) try BufferedReader br = new BufferedReader( new InputStreamReader(System.in); ai = Integer.parseInt(br.readLine( ); catch ( IOException e ) ; int s=0; for (int i

9、 = 0 ; i a.length ; i+ ) s+=ai; System.out.print(s); 四、 改错题1、public static void main(String args )try/省略catch(Exception e)return;catch(IOException e)System.out.println(e.toString();2、public class WrongOrRight implements RunnableThread mt=new Thread(this);mt.start();void run()System.out.println(“I am

10、 alive now”);五、 程序设计题1、假设某一整数数组中的数值是由小到大存放的,编写一个字符界面的二分查找Java Application ,在数组中查找某一通过键盘输入的数值,输出该数值在数组中的位置。2、阅读以下程序段,假定服务器端和客户端程序正常运行无异常发生,请回答以下问题:描述程序功能。假定在客户端输入2.0,请写出服务器端的输出结果。 /服务器端程序import java.io.*;import .*;public class Server public static void main(String args) try ServerSocket serverSocket

11、= new ServerSocket(8000); Socket connectToClient = serverSocket.accept(); DataInputStream isFromClient = new DataInputStream( connectToClient.getInputStream(); DataOutputStream osToClient = new DataOutputStream( connectToClient.getOutputStream(); while (true) double value = isFromClient.readDouble()

12、; System.out.println(value received from client: +value); double result = value*value; osToClient.writeDouble(result); osToClient.flush(); System.out.println(result: + result); catch(IOException ex) System.err.println(ex); /客户端程序import java.io.*;import .*;public class Client public static void main(

13、String args) try Socket connectToServer = new Socket(localhost, 8000); DataInputStream isFromServer = new DataInputStream( connectToServer.getInputStream(); DataOutputStream osToServer = new DataOutputStream(connectToServer.getOutputStream(); while (true) System.out.print(Please enter a double value

14、: ); double value=Double.parseDouble(new BufferedReader(new InputStreamReader(System.in),1).readLine(); osToServer.writeDouble(value); osToServer.flush(); double result = isFromServer.readDouble(); System.out.println(result received from the server is + result); catch (IOException ex) System.err.pri

15、ntln(ex); 3、编写一个完整的Java Application 程序。包含抽象类Shape、MyCircle类及Test类,具体要求如下:抽象类Shape:double getArea():求一个形状的面积 double getPerimeter ():求一个形状的周长类MyCircle:由Shape类派生的具体类,除实现Shape类中的方法外,另有以下成员变量和方法:Radius:double类型,表示圆的半径MyCircle(double r):构造方法 toString()方法 :输出圆的描述信息,如“radius=1.0, perimeter=6.28, area=3.14”

16、Test类作为主类要完成测试功能生成MyCircle对象, 调用对象的toString方法,输出对象的描述信息参考答案一、 填空题1、Public(公共) 2、抽象3、HTML 4、javac.exe 3 .class5、run方法 二、 单项选择题15:CBAAA 610:CACAC三、 程序阅读题1、从键盘逐一输入字符串,逐一输出至input.txt文件中,直至输入空行。2、程序发生异常,捕获异常后并输出:IO Exception3、15四、 改错题1、捕获异常应将具体的异常类参数置前,题中将Exception类置前,将捕获所有异常,无法进入其他catch块。改正如下:public sta

17、tic void main(String args )try/省略 catch(IOException e)System.out.println(e.toString();catch(Exception e)return;2、run()方法作为接口中的方法缺省是public的, 题中缩小了范围。改正如下:public class WrongOrWrite implements RunnableThread mt=new Thread(this);mt.start();public void run()System.out.println(“I am alive now”);五、 程序设计题1、

18、import java.io.*;class FindSearch int binarySearch(int arr,int searchValue) int low=0; / low是第一个数组元素的下标 int high=arr.length-1; / high是最后一个数组元素的下标 int mid=(low+high)/2; / mid是中间那个数组元素的下标 while(low=high & arrmid!=searchValue) if( arrmidhigh) mid=-1; return mid; / mid是数组元素下标,若为-1则表示不存在要查的元素 public clas

19、s chazhao public static void main(String args)throws IOException BufferedReader keyin=new BufferedReader(new InputStreamReader(System.in); int i,k,search,mid; String c1; int arr=2,4,7,18,25,34,56,68,89; System.out.println(打印原始数据); for(i=0;iarr.length;i+) System.out.print( +arri); System.out.println(

20、n); System.out.println(请输入要查找的整数); c1=keyin.readLine(); search=Integer.parseInt(c1); FindSearch p1=new FindSearch(); mid=p1.binarySearch(arr,search); if(mid=-1) System.out.println(没找到!); else System.out.println(所查整数在数组中的位置下标是:+mid); 2、客户端发送一个实数,服务器端接收并计算该数的平方,然后将求得的平方值发回至客户端显示。客户端可继续向服务器发送直至有一方退出。value received from client: 2.0result found: 4.03、略

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 科普知识


经营许可证编号:宁ICP备18001539号-1