• <nav id="cwumo"><code id="cwumo"></code></nav>
  • <menu id="cwumo"><strong id="cwumo"></strong></menu>

    java常見面試題

    時間:2020-12-07 10:59:31 面試問題 我要投稿

    java常見面試題

    用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<num ;i++ )
    {
    al.add(new Integer(Math.abs(rand.nextInt()) % mod + 1));
    System.out.println(”al["+i+"]=”+al.get(i));
    }
    }
    public void SortIt()
    {
    Integer tempInt;
    int MaxSize=1;
    for(int i=1;i<al.size();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<MaxSize ;j++ )
    {
    if

    java常見面試題

    (((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<al.size();i++)
    {
    System.out.println(”al["+i+"]=”+al.get(i));
    }
    }
    public static void main(String[] args)
    {
    InsertSort is = new InsertSort(10,100);
    is.SortIt();
    }
    }

     

    更多相關的文章推薦,大家敬請關注應屆畢業生求職網的面試問題欄目!

    【java常見面試題】相關文章:

    2017年java常見面試題及答案11-11

    精選Java線程面試題06-15

    java基礎面試題201711-13

    華為Java面試題精選10-24

    高級Java面試題匯總09-12

    2016年JAVA面試題11-07

    2017年java華為面試題08-20

    經典的Java基礎面試題08-22

    JAVA經典面試題目匯總10-12

    java程序員面試題08-27

    日韩激情