`
jia106329
  • 浏览: 60985 次
  • 性别: Icon_minigender_2
  • 来自: tj
社区版块
存档分类
最新评论

改错误

阅读更多
今天公司面试四个小朋友,想起了我们之前面试的情景,没想到今年还要面试机试,就是找错误。呵呵

他们穿的衣服好像是做推销的,一水的黑西装,女生也是,刚到公司的门口的时候看到他们确实吓了一跳呢,呵呵


下面就是源码

public class SingleSimple {
	private static int index = 1;
	protected SingleSimple(){
		index+= 1;
	}
	
	protected SingleSimple(String[] hello1,String[] hello2){
		index+= 1;
		hello2 = hello;
		hello = hello1;
	}
	
	private String[] hello={"1","2","3","4","5","6","7"};
	public static SingleSimple getEntity(){
		return new SingleSimple();
	}
	
	public String[] getHello() {
		return hello;
	}

	public void setHello(String[] hello) {
		this.hello = hello;
	}

	public void runArray(){
		try{
			if(hello.length == 0 || hello == null){
				System.out.println("hello error");
			} else if(hello.length != 0){
				for (int i = 0; i < hello.length; i++) {
					if(hello[i].equals("1")){
						System.out.println("1");
					} else if(hello[i].equals("1")){
						System.out.println("1");
					}  else if(hello[i].equals("2")){
						System.out.println("2");
					}  else if(hello[i].equals("3")){
						System.out.println("3");
					}  else if(hello[i].equals("4")){
						throw new Exception("4");
					}  else if(hello[i].equals("5")){
						System.out.println("5");
					}   else if(hello[i].equals("6")){
						System.out.println("6");
					}   else if(hello[i].equals("7")){
						System.out.println("7");
					} 
				}
			}
		} catch(Exception E){
			E.printStackTrace();
		}
	}
	
	private void helloworld(){
		try {
		if(index > 2){
				throw new Exception();
		}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}



public class TestFactory {
	private static SingleSimple ss = null;
	private String[] a;
	private String[] b;
	
	private TestFactory () { }
	
	public synchronized static SingleSimple newInstance(){
		if(ss == null){
			ss = new SingleSimple();
		}
		return ss;
	}
	
	public String[] display(){
		ss = new SingleSimple(a,b);
		ss.runArray();
		this.xy();
		return ss.getHello();
	}
	
	private void xy(){
		ss.setHello(b);
		ss.runArray();
	}
	
	public static void main(String[] args){
		TestFactory t = new TestFactory();
		SingleSimple x = t.newInstance();
		String[] h = t.display();
		String[] temp = new String[3];
		int n = 0;
		for (int i = 0; i <= h.length; i++) {
			if(i%2 != 0){
				temp[n]=h[i];
				n ++;
			}
		}
		x.setHello(temp);
	}
}

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics