为大家谋福利的我给大家贴个面试题,是今天我一个软件公司面试的。

TONYBLARED 2006-03-21 08:36:25
1. 有一个ArrayList,里面包含N个Integer,其中的Integer都是由1至N+1的数字构成,并且不重复,但是有一个1至N+1的数字对应的Integer

不存在ArrayList中,求该数。

public static void main(String[] args){

ArrayList list= new ArrayList();
list.add(Integet(7));
list.add(Integet(8));
list.add(Integet(1));
list.add(Integet(2));
list.add(Integet(3));
list.add(Integet(4));
list.add(Integet(5));

}


public int getMissing(ArrayList list){
int len = list.size();
for (int i = 1; i <= len; i++) {
int j = 0;
while (j < len) {
Integer Val = (Integer) list.get(j);
int value = Val.intValue();
if (i == value)
break;
j++;
}
if (j == len) {
return j;
}
}
return -1;
}

2. 有一个二叉树类如下。然后写出遍历二叉树的方法printTree。
class BinaryTree{
class Node{
String value;
Node leftNode;
Node rightNode;
}
public void printTree(Node root){
reDo(root,0);
}

public void reDo(Node node,int depth){
if(node != null) {
System.out.println(space()+node.value);
reDo(node.leftNode,depth+1);
reDo(node.rightNode,depth+1);
}

}

public String space(int len){
StringBuffer bs = new StringBuffer();
for(int i=0; i<bs.length();i++){
bs.append(" ");
}
}
}

3. 有int型数字如下,123,1234,12345,123456,1234567,12345678,123456789
求一个方法,输出123 1,234 12,345 123,456 1,234,567 12,345,678 123,456,789

public String printComma(int input){
StringBuffer bs = new StringBuffer(input + "");
int index = bs.length() - 3;
while (index > 0) {
bs.insert(index, ",");
index = index - 3;
}
return bs.toString();
}

4.equals(),hasCode()的作用。

5.Object对象有哪些方法?
equals(),clone(),notify(),notifyAll(),wait(),wait(long time),wait(long time,int nanos)
hasCode(),toString(),getClass()。

6.RuntimeException,非RuntimeException的区别和例子。

7.Singleton模式

8.共享数据在web中的范围
page,request,seesion,application

9.Servlet的生命周期。
servlet有良好的生存期定义,包括加载,实例化,初始化,处理请求,服务结束。由javax.servlet.Servlet接口以下方法表达
init(),service(),destroy()。

10.abstract和interface的区别。
abstract中可以有自己方法的定义和说明,interface只是存在变量和方法的定义。当需要的时候,我们可以inplements多个接口,但是只能

extends一个类。

11.实现多线程有哪几种方法。
第一种,class MyThread extends Thread{..} MyThread t = new MyThread(); t.start();
第二中,class UrThread implements Runnable{...} Thread t = new Thread(new UrThread()); t.start();

12.ArrayList和Vector的区别。
Vector中的方法是synchronized的,性能上较ArrayList差点。
当增长时,Vector默认增长原来的一倍,ArrayList默认增长原来的一半。

13.java实现序列化的方法是实现serializable接口,具体怎么做。

14.String a = "test"; String b = new String("test"); a==b (false)
String c = "te"+"st"; a==c (true)

15.
public synchronized void aMethod1(){

}

public void b aMethod(){
synchronized("test"){

}
}

A a1 = new A();
A a2 = new A();

a1.aMethod1();
a2.aMethod1();//不需要等待

a1.aMethod2();
a2.aMethod2();//需要等待

16.编程性能方法的讨论,ArrayList,HashMap,StringBuffer。

17.Struts的DispatchAction,Action的区别。RequestProcessor的作用。
...全文
1475 52 打赏 收藏 转发到动态 举报
写回复
用AI写文章
52 条回复
切换为时间正序
请发表友善的回复…
发表回复
chaosking 2006-04-13
  • 打赏
  • 举报
回复
楼主,你们公司还招人么?
TONYBLARED 2006-04-13
  • 打赏
  • 举报
回复
tolimit(没有把握就永远没有幸运):
你面试的是什么公司,能方便提示一下吗?
TONYBLARED 2006-04-13
  • 打赏
  • 举报
回复
是的,招人。
老大让推荐,最好是有经验的,对自己有自信的就跟我谈谈28130832qq[兰陵笑笑生]。
taoning 2006-04-12
  • 打赏
  • 举报
回复
狂顶!!!
sail988 2006-04-12
  • 打赏
  • 举报
回复
无所不在的二分查找(Programing pearls)
javaboat 2006-04-12
  • 打赏
  • 举报
回复
学习一下!
vickcy 2006-04-12
  • 打赏
  • 举报
回复
恭喜搂主!
ziqi_wy 2006-04-12
  • 打赏
  • 举报
回复
本科的时候真该好好学习来着:)
tolimit 2006-04-12
  • 打赏
  • 举报
回复
LZ和我今天面试的公司题目有一半是一样的,可惜我没做好,好多不会,郁闷死了!
面试的人亲切的让我找合适的新单位:(
iamlain 2006-04-12
  • 打赏
  • 举报
回复
3. 有int型数字如下,123,1234,12345,123456,1234567,12345678,123456789
求一个方法,输出123 1,234 12,345 123,456 1,234,567 12,345,678 123,456,789

这个题的逻辑关系没看出来
不知道能不能用数学的处理方法来做
// 123,
// 1234 - 1000 = 234
// 12345 -12000 = 345 123
// 123456 - 123000 = 456 1
// 1234567 - 1234000 = 567 12
// 12345678 - 12345000 = 678 123
// 456
// 789
iamlain 2006-04-12
  • 打赏
  • 举报
回复
public getValue(ArratList list){

/*count:1--n+1的总和*/
int count=0;
/*集合里整数的总和*/
int listcount=0;
/*集合的有效空间,长度*/
int length=0;
/*所求的值*/
int value=0;

length=list.size();

count=(1+length+1)*n/2;

for(int i=0;i<length;i++)
listcount=(Integer)list.get(i).intValue()+listcount;

value=count-listcount;
return value;
}

这个算法没有看明白 N是什么
iamlain 2006-04-12
  • 打赏
  • 举报
回复

public class Arraysort {
static final Integer[] data = {
new Integer(1),
new Integer(2),
new Integer(3),
new Integer(5),
new Integer(4),
new Integer(8),
new Integer(7),
new Integer(10),
new Integer(9),
};

static int count =0;
static int getMissing(){
int result=-1;
boolean flag = true;
for(int i=1;i<data.length+1;i++){
flag = false;
for(int j=0;j<data.length;j++){
if(data[j].intValue() == i ){
flag = true;
count +=1;
break;
}
}
if(!flag)
result = i;
}
return result;
}

public static void main(String[] avg){

System.out.println(Arraysort.getMissing());
System.out.println(Arraysort.count);


}
NerGP 2006-04-11
  • 打赏
  • 举报
回复
对于第一道题的求值,由于很有规律性,可以用另外一种思路:1+2+...+N+1的值 减去集合里面的总和

public getValue(ArratList list){

/*count:1--n+1的总和*/
int count=0;
/*集合里整数的总和*/
int listcount=0;
/*集合的有效空间,长度*/
int length=0;
/*所求的值*/
int value=0;

length=list.size();

count=(1+length+1)*n/2;

for(int i=0;i<length;i++)
listcount=(Integer)list.get(i).intValue()+listcount;

value=count-listcount;
return value;
}

代码我可能不好,但我觉得最有意思的就是对一个问题有不同的思路,不管好的思路还是差的思路,
刚来论坛不久,希望和大家交朋友
abpeng 2006-04-11
  • 打赏
  • 举报
回复
!!!!!!!!!!
water621 2006-04-11
  • 打赏
  • 举报
回复
收藏
TONYBLARED 2006-04-11
  • 打赏
  • 举报
回复
我们公司招人,我负责推荐的,然后我拿楼主的第三题去试了一下群里的选手,都不行,哎。现在整的,都什么IT人士啊。
huangdeji 2006-04-01
  • 打赏
  • 举报
回复
ArrayList list= new ArrayList();
list.add(new Integer(7));
list.add(new Integer(8));
list.add(new Integer(1));
list.add(new Integer(2));
list.add(new Integer(3));
list.add(new Integer(4));
list.add(new Integer(5));
int obj = 0;
for(int i = 1;i < 9;i++){
if(list.indexOf(new Integer(i)) == -1){
obj = i;
}
}
System.err.println("" + obj);
scjpsz1860 2006-04-01
  • 打赏
  • 举报
回复
恭喜楼主了!:)
QQ10460850 2006-04-01
  • 打赏
  • 举报
回复
第一题的这个ArrayList里面包含的N个Integer没说一开始是从小到大排的咧??
Hmilyl 2006-03-31
  • 打赏
  • 举报
回复
恭喜LZ,要努力学习拉~~~~~
加载更多回复(32)

62,625

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧