JAVA期末试题集(含答案) 下载本文

内容发布更新时间 : 2024/5/21 1:48:59星期一 下面是文章的全部内容请认真阅读。

A.mousePressed() B.keyPressed()

C.Event() D.actionPerformed()

18、下列哪个不是类的修饰符( )

A.frame B.public

C.final D.abstract

19、方法abc()有逻辑型返回值,定义时下列哪个方法是正确的( ) A.void

abc(){ } B.String abc(){ }

C.boolean abc(){ } D.static void abc(){ }

20、已知服务器IP为192.168.0.3,端口为80,客户端要与服务器通信,要先创建Socket对象,正确语句为( )

A.ServerSocket s=new ServerSocket(“192.168.0.3”,80) B.ServerSocket s=new ServerSocket(80) C.Socket s=new Socket(“192.168.0.3”,80) D.Socket s=new Socket(80)

二、程序填空题

1.以下是用来输入并显示输入内容的小程序,请将空白处填充完整。 [1] java.io.*; public class xyz{

public static [2]___ main(String args[]){

[3] abc=””;

BufferedReader b =new BufferedReader(new

InputStreamReader(System.in));

System.out.println(\输入字符串:\try{

abc= __[4]__.readLine(); }catch(Exception e){ }

System.out.println(\输入的内容为:\ }

[5]

2.以下是输出1-100之间所有奇数的小程序,请将空白处补充完整。 public class Pdjs {

public static void main(String args[]){ [6] p=new Pdjs(); System.out.println(\奇数为:\for (int n=1;n<=100;[7] ){ if(p.JS(n)) System.out.print(n+\\} }

[8] JS(int [9] ){ if(i%2==0) return true; else return [10] ; } } 三、编程题

1.编写一个完整的JAVA小程序,用于计算100到200之间的所有被3整除的奇数和,并输出计算结果。

2. 已知圆球体积公式为,编写一程序,设计一个求圆球体积的方法,并在主程序中调用它,求出当r=3时,圆球的体积值。

四、项目分析题

以下是书目信息管理系统的部分源代码,现要求针对该项目进行分析,并完成以下内容:

1.分析该项目的算法部分设计思路; 2.将书目信息修改代码段补充完整。

import javax.swing.*; ......(其他类包的引入省略) public class TSGL extends JFrame {

JLabel title =new JLabel(\简易书目信息管理系统\JLabel sm =new JLabel(\书名\ JLabel zz =new JLabel(\作者\

JLabel cbs =new JLabel(\出版社\ JLabel jg =new JLabel(\价格\

JLabel flh =new JLabel(\分类号\ JLabel cch =new JLabel(\财产号\JTextField tsm =new JTextField(); JTextField tzz =new JTextField(); JTextField tcbs=new JTextField(); JTextField tjg =new JTextField(); JTextField tflh=new JTextField(); JTextField tcch=new JTextField(); JButton add =new JButton(\添加\

JButton search=new JButton(\查找\JButton modify=new JButton(\修改\ JButton delete=new JButton(\删除\JButton quit =new JButton(\退出\public static void main(String[] args){

TSGL ts =new TSGL(); ts.setSize(500,500); ts.show(); } TSGL(){

Container cc=getContentPane(); cc.setLayout(null);

//以下是各个对象在界面上的布局设置(代码省略) ......

add.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ String str=\

str=tsm.getText()+\\

……//部分代码省略

BufferedReader fin1 = new BufferedReader(new

FileReader(\

while ((temp1=fin1.readLine())!=null) temp2+=temp1+\temp2+=str;

BufferedReader fin2 =new BufferedReader(new

StringReader(temp2));

PrintWriter fout=new PrintWriter(new BufferedWriter(new FileWriter

(\

while ((temp1=fin2.readLine())!= null)