我要投稿 投诉建议

常见java面试题

时间:2021-02-25 11:05:41 面试试题 我要投稿

常见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

(((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();
}
}

http://jianlimoban.c321.cn/

【常见java面试题】相关文章:

Java软件测试面试题06-20

java多线程面试题03-19

Java的面试题和答案10-30

公司JAVA开发面试题06-03

java前端开发面试题05-09

关于Java泛型的面试题04-12

华为的Java面试题及答案11-22

最新JAVA实现链表面试题10-24

最常见的面试题09-17

常见软件测试面试题05-10