二、填空题 (1)对象串行化可以很容易地扩展成支持Java对象的 [1],它提供了对象从流中重建的补充方式. (2)Vector类的对象是通过capacity和capacityIncrement两个值来改变集合的容量,其中capacity表示集合最多能容纳的 [2] ,capacityIncrement表示每次增加多少容量,不是一个一个增加. (3)下列程序的功能是判断某一年是否为闰年.请在横线处填入适当内容,使程序能够正确运行. import java.io.*; public class LeapYear{ public static void main(String arge[])throws IOException{ InputStreamReader ir; BufferdeReadwe in; ir=new InputStreamReader(System.in); in=new BufferedReader(ir); System.out.println(“输入年份是:”); String s= [3] ; int year=Integer.parseInt(s); if (year % 4 = = 0 && year % 100! = 0 // year % 400 = = 0) { System.out.println(""+year+"年是闰年."); } else { System.out.println(""+year+"年不是闰年.."); } } }
(4)下面程序对数组中每个元素赋值,然后按逆序输出.请在横线处填入适当内容,使程序能正常运行. import java.io.*; public class ArrayTest{ public static void main(String args[]){ int i; int a[] = new int[5]; for(i=0;i<5;i++) a[i]=i; for( [4] ;i>=0;i- -) System.out.println("a["+i+"]="a[i]); } }
(5) 下列程序的功能是:输入一个姓名,程序运行后,输出“姓名Welcome you!”.例如,输入“张三Welcome you !”.请在下面横线处填入正确的方法名,使程序可以正确运行. import java,awt,*; import java.awt.event.*; public class welcomenYou{ public static void main(String args[]) { new FrameInOut(); } } class FrameInOut extends Frame implements ActionListener { Label prompt; TextField input,output; Button btnn; void FramInOut() { prompt=new Label("Please input your name"); input=new TextField(10); output=new TextField(25); btnn=new Button("Class"); [5] (new FlowLayout()); add(prompt); add(input); add(output); add(btnn); input.addActionListener(this); btnn.addActionListener(this); setSize(300.200); show(); }
public class FindMax extends Applet implements ActionListener{ Label result; TextField in1,in2; Button btn; int a=0,b=0,max;
public void init(){ result = new Label"请先输入两个待比较的整数"); in1=new TextField(5); in2=new TextField(5); btn=new Button("比较"); add(in1); add(in2); add(btn); add(result); btn.addActionListener(this); } public void actionperformed(ActionEvent e){ a=in1; n=in2; if(a>b) max=a; else max=b; btn.setText("两个数中最大值是:"+max); } }
findmax.html:
参考答案: 公共基础知识: 一:选择题: (1) D (2) C (3) D (4) B 二:填空题: (1)[1]:O(Nlog2N) (2)[2]:功能模型 (3)[3]:软件外部功能 (4)[4]:二维表 Java程序设计: 一:选择题: 1-5 :B D D C C 6-10:B A A B D 二:填空题: (1)[1]:持续存储或持久存储 (2)[2]:元素个数 (3)[3]:in.readLine() (4)[4]:i=a.Length-1 (5)[5]:setLayout