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的作用。
posted on 2006-03-22 15:53
xnabx 閱讀(221)
評論(0) 編輯 收藏