应聘Java笔试时可能出现问题及其答案(二)


作者:无风浪 | 来源:Examlink | 日期:07-27 | 字体: [ ]

本文简介:用JAVA实现一种排序,JAVA类实现序列化的方法(二种)? 如在COLLECTION框架中,实现比较要实现什么样的接口?

      

     socket = new Socket("127.0.0.1",10000);
     System.out.println("The Server Connected!");
     System.out.println("Please enter some Character:");
     BufferedReader line = new BufferedReader(new

     InputStreamReader(System.in));
     out = new PrintWriter(socket.getOutputStream(),true);
     out.println(line.readLine());
     in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
     System.out.println(in.readLine());
     out.close();
     in.close();
     socket.close();
    }
    catch(IOException e)
    {
     out.println("Wrong");
    }
   }
   public static void main(String[] args)
   {
    new Client();
   }
  };

  14、用JAVA实现一种排序,JAVA类实现序列化的方法(二种)? 如在COLLECTION框架中,实现比较要实现什么样的接口?

  答:用插入法进行排序代码如下
  package test;
  import java.util.*;
  class  InsertSort
  {
   ArrayList al;
   public InsertSort(int num,int mod)
   {
    al = new ArrayList(num);
    Random rand = new Random();
    System.out.println("The ArrayList Sort Before:");
    for (int i=0;i) 
    {
     al.add(new Integer(Math.abs(rand.nextInt()) % mod + 1));
     System.out.println("al["+i+"]="+al.get(i));
    }
   }
   public void SortIt()
   {
    nteger tempInt;
    int MaxSize=1;
    for(int i=1;i  )
    {
     tempInt = (Integer)al.remove(i);
     if(tempInt.intValue()>=((Integer)al.get(MaxSize-1)).intValue())
     {
      al.add(MaxSize,tempInt);
      MaxSize++;
      System.out.println(al.toString());
     }
     else
     {
      for (int j=0;j)    
      {
       if (((Integer)al.get(j)).intValue()>=tempInt.intValue())
       {
        al.add(j,tempInt);
        MaxSize++;
        System.out.println(al.toString());
        break;
       }
      }
     }
    }
    System.out.println("The ArrayList Sort After:");
    for(int i=0;i) 
    {
     System.out.println("al["+i+"]="+al.get(i));
    }
   }
   public static void main(String[] args)
   {
    InsertSort is = new InsertSort(10,100);
    is.SortIt();
   }
  }

  JAVA类实现序例化的方法是实现java.io.Serializable接口
  Collection框架中实现比较要实现Comparable 接口和 Comparator 接口




用户名: 新注册) 密码: 匿名评论 [所有评论]

评论内容:(不能超过250字,需审核后才会公布,请自觉遵守互联网相关政策法规。
  • 2007年国家计算机等级考试 JAVA认证 JAVA真题 JAVA模拟试题
如果你觉得一篇文章有用,你可以在每篇后面参与评论,或者查看其他人的评论,请保证你的评论对大家友好。
点这里评论
或者您可以来资源论坛参与讨论,一切都是免费的,不过可能需要麻烦您注册一下。
点这里讨论
把你的文章登陆在这里,让大家来分享你的文章。请立即登陆发表!
点这里投稿