全国计算机等级考试二级Java样题
来源:优易学  2010-1-15 9:41:09   【优易学:中国教育考试门户网】   资料下载   IT书店

 

  二、填空题
  (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 void actionperformed(ActionEvent e)
  {
    if(e.getSource() = = input)
      output.setText(input.getText()+"Welcome you!");
    else
    {
      dispose();
      system.exit(0);
    }
  }
  }

上一页  [1] [2] [3] [4] 下一页

责任编辑:cyth

文章搜索:
 相关文章
热点资讯
资讯快报
热门课程培训