日期:2014-05-20  浏览次数:20965 次

IBM中国研究院面试题
前几天接到IBM研究院的面试电话,谈了几句,然后那边给我发了一道编程题,把答案发过去几天后,今天接到复试电话,于是下午过去了一趟,先是又进行了30分钟的笔试,然后进来4个人(据说都是博士),像开批斗会一样的围着我,那会儿太过紧张,以致后面的问题都答得不好!
下面是IBM的笔试题目:
请模拟银行某一时段的服务流程(一小时内完成)
银行有4个服务窗口,其中有三个是普通窗口,一个是VIP窗口。VIP窗口在没有VIP用户时也可以当作普通服务窗口办理业务。银行的服务流程描述如下:
首先到达的客户需要在门口领取一张号码纸,号码纸上写明了前面排队的人数和你的号码。
客户等待自己被服务。如果号码纸的的号码过期,即当前的号码大于号码纸的号码,则号码纸就过期了
如果VIP用户到达后,VIP用户进入VIP窗口办理,如果VIP窗口前面有其他的VIP用户,则排在其他VIP用户之后,如果有普通会员在办理,则服务完成后立刻服务VIP用户。
银行的业务员在服务完一个客户后,会根据号码纸依次通知下一个客户进行服务
以下是数据:
1 普通 09:00 5
2 普通 09:00 6
3 普通 09:00 5
4 普通 09:02 9
5 普通 09:04 5
6 VIP 09:05 7
7 普通 09:10 5
8 普通 09:12 10
9 普通 09:15 5
10 VIP 09:18 5
11 普通 09:18 8
12 普通 09:19 5
13 VIP 09:21 9
14 普通 09:21 5
15 普通 09:26 5
16 普通 09:27 2
17 普通 09:28 5
18 普通 09:29 10
19 普通 09:29 5
20 VIP 09:32 5
21 普通 09:32 6
22 普通 09:32 5
23 VIP 09:33 12
24 VIP 09:40 5
25 普通 09:40 5
26 普通 09:45 5
27 普通 09:46 5
28 普通 09:46 5
29 VIP 09:51 5
30 普通 09:51 5
31 VIP 09:55 5
32 普通 09:58 5


今天的笔试题目只记得一部分(总共7道题):
Java code

1.写出下面代码的执行结果:
public class T {
    

    public static void main(String[] args) {
        Byte b=new Byte("127");
        System.out.println(b.toString()==b.toString());
              
    }
}

2.写出下面代码的执行结果:
package com.ibm.bmcc.test;

public class T {
    

    public static void main(String[] args) {
        method1();
        System.out.println("f");
    }
    
    static void method1(){
        try{
            method2();
            System.out.println("a");
        }catch (NullPointerException e) {
            System.out.println("b");
        }finally{
            System.out.println("c");
        }
        System.out.println("d");
    }
    
    static void method2(){
        System.out.println("e");
        throw new IllegalStateException();
    }
    
    
    
}
3.用Java实现一个单利模式
4.多线程编程,第一个线程负责对某个数加一,第二个线程负责对这个数减一


有兴趣的朋友可以看一下,面试总结:听着IBM研究院的名字挺吓人的,但是没想到这笔试题都是非常的基础,各位兄弟,还是把基础打牢吧!

------解决方案--------------------
探讨

Byte b=new Byte("127");
System.out.println(b.toString()==b.toString());


可有哪位高手能解释一下为什么会输出false呢?

------解决方案--------------------
Java code

public class BankQueueThread {
    
    private static List<CustomerInfo> queue= Collections.synchronizedList(new ArrayList<CustomerInfo>());
    private static List<String> vipqueue= Collections.synchronizedList(new ArrayList<String>());
    private static int num=0;
    private static int rnum=0;
    private SimpleDateFormat datef=new SimpleDateFormat("HH:mm");
    public static void main(String args[]) {
        BankQueueThread bankQueueThread=new BankQueueThread();
        AddUser adduser=bankQueueThread.new AddUser();
        Thread th= new Thread(adduser);
        th.start();
        
        for(int i=0;i<3;i++){
            OrderNormalQueue orn=bankQueueThread.new OrderNormalQueue();
            th= new Thread(orn);
            th.start();
        }
        OrderVIPQueue orv=bankQueueThread.new OrderVIPQueue();
        th= new Thread(orv);
        th.start();
    }
    //增加普通用户排队
    public synchronized void addUser(int nums){
        String s=""+(++num);
        CustomerInfo customerInfo=new CustomerInfo();
        customerInfo.setType("普通");
        customerInfo.setId(s);
        customerInfo.setFtime(nums);
        customerInfo.setStime(datef.format(new Date()));
        queue.add(customerInfo);
    }
    //增加VIP排队
    public synchronized void addVipUser(int nums){
        String s=""+(++num);
        CustomerInfo customerInfo=new CustomerInfo();
        customerInfo.setType("VIP");
        customerInfo.setId(s);
        customerInfo.setFtime(nums);
        customerInfo.setStime(datef.format(new Date()));
        queue.add(customerInfo);
        vipqueue.add(s);
    }
    //普通窗口假设处理业务
    public synchronized void removieUser(){
        CustomerInfo cus=null;
        if(queue.size()>0){
            rnum++;
            cus=(CustomerInfo)queue.remove(0);
        
            if(vipqueue.size()>0&&vipqueue.get(0).equals(cus.getId())){
               vipqueue.remove(0);
               System.out.println(Thread.currentThread().getName()+":>> "+rnum+" "+cus.getId()+" "+cus.getType()+" "+cus.getStime()+" "+cus.getFtime()+" <<办理业务完毕");
           }else{
               System.out.println(Thread.currentThread().getName()+":>> "+rnum+" "+cus.getId()+" "+cus.getType()+" "+cus.getStime()+" "+cus.getFtime()+" <<办理业务完毕");
           }
        }
    }
    //VIP窗口假设处理业务
    public synchronized void removieVipUser(){
        String d="";
        CustomerInfo cus=null;
        if(vipqueue.size()>0){
          rnum++;
          d=vipqueue.remove(0);
          for(int i=0;i<queue.size();i++){
              cus=(CustomerInfo)queue.get(i);
            if(cus.getId().equals(d)){
              queue.remove(i);
              System.out.println(Thread.currentThread().getName()+":>> "+rnum+" "+cus.getId()+" "+cus.getType()+" "+cus.getStime()+" "+cus.getFtime()+" <<办理业务完毕");
              break;
            }
          }
        }else if(queue.size()>0){
              rnum++;
              cus=(CustomerInfo)queue.remove(0);
              System.out.println(Thread.currentThread().getName()+":>> "+rnum+" "+cus.getId()+" "+cus.getType()+" "+cus.getStime()+" "+cus.getFtime()+" <<办理业务完毕");
        }
        
    }

    //用户排队
    class AddUser implements Runnable{
        Random rd=new Random();
        int sd=0;
        public void run() {
            // TODO Auto-generated method stub
            while(true){
            sd=rd.nextInt(10);
            if(sd==8){
                addVipUser(sd);
            }else{
                addUser(sd);
            }
            if(queue.size()>=100){
                try {
                    Thread.sleep(5000);
                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
            }
            
        }
        
    }
    //普通窗口业务受理
    class OrderNormalQueue implements Runnable{
        public void run() {
            // TODO Auto-generated method stub
            while(true){
            
              removieUser();
              try {
                Thread.currentThread().sleep(1000);
              } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
              }
            }
        }
        
    }
    //VIP窗口业务受理
    class OrderVIPQueue implements Runnable{

        public void run() {
            // TODO Auto-generated method stub
            while(true){
            removieVipUser();
            try {
                Thread.currentThread().sleep(1000);
              } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
              }
            }
        }
        
    }
    
    class CustomerInfo{
        
        private String stime;
        private String id;
        private String type;
        private int ftime;
        public String getStime() {
            return stime;
        }
        public void setStime(String stime) {
            this.stime = stime;
        }
        public String getId() {
            return id;
        }
        public void setId(String id) {
            this.id = id;
        }
        public String getType() {
            return type;
        }
        public void setType(String type) {
            this.type = type;
        }
        public int getFtime() {
            return ftime;
        }
        public void setFtime(int ftime) {
            this.ftime = ftime;
        }
    }
    

}