java常見面試題

來源:瑞文範文網 2.11W

用java實現一種排序,java類實現序列化的方法(二種)? 如在collection框架中,實現比較要實現什麼樣的接口?
答:用插入法進行排序代碼如下
package test;
import .*;
class insertsort
{
arraylist al;
public insertsort(int num,int mod)
{
al = new arraylist(num);
random rand = new random();
tln(”the arraylist sort before:”);
for (int i=0;i<num ;i++ )
{
(new integer((int()) % mod + 1));
tln(”al["+i+"]=”+(i));
}
}
public void sortit()
{
integer tempint;
int maxsize=1;
for(int i=1;i<();i++)
{
tempint = (integer)ve(i);
if(alue()>=((integer)(maxsize-1))alue())
{
(maxsize,tempint);
maxsize++;
tln(ring());
} else {
for (int j=0;j<maxsize ;j++ )
{
if

java常見面試題

(((integer)(j))alue()>=alue())
{
(j,tempint);
maxsize++;
tln(ring());
break;
}
}
}
}
tln(”the arraylist sort after:”);
for(int i=0;i<();i++)
{
tln(”al["+i+"]=”+(i));
}
}
public static void main(string[] args)
{
insertsort is = new insertsort(10,100);
it();
}
}

熱門標籤