面试题:这些题是一家单位给我面试的,那位仁兄能做?
   现我把题目公布出来,供大家参考:该写的我都贴出了,有不清楚的大家也不要问我,我也不清楚
题1、write a program to judge whether a number is "loop number" 
such as 12321,574765 with java programming language.
题2、what's design pattern please describe one or two design 
pattern(s)used in your project.题3、please draw correct associction notations in this diagram,
     and then convert the  diagram to java souce code       _______________             _________________
      |(interface)   |             |   Machine     |
      | Drirable     |             |_______________|
      |______________|             |_______________|
      |+tarnlefor    |
      |+trunRight    |
      |______________|
 
      ________________              _______________
      |   Car        |             |   Wheel      |
      |______________|             |______________|
      |______________|             |______________|
题4、
   public final  class Test4{
 
   class inner{
   void test(){
   if(Test4.this.flag){
     sample();
}
}
}
  private boolean flag=false;
  public void sample(){
   system.out.println("sample");}   
  Public void Test4(){
  (new inner()).test();
}
Public static void main(Strung args[]){
 new Test4();
}
}
    题5、
   Public class Demo{
    Public static  void main(String args[]){
    int n=3
    System.out.println("the word is"+args[n]);
   
}
}
 what happens?
a)b)c) the runtine system reports an ArrayindexoutofBoundException in the 
   maun method.d)Then runtime system reports a NullPointerException in the main method.

解决方案 »

  1.   

    兄弟,这样的题都不会作的话,还面试吗??第一个题是纯粹的算法题,于Java毫无关系,第二个题只要看过<<Thinking in Java>>一遍,我想就不只一种设计模式了吧,第三个问题是个最简单的UML图,继承,接口的关系,第四个问题内部类,第五个是个异常,java.lang.ArrayIndexOutOfBoundsException!
      

  2.   

    我也知道,第一个题是纯粹的算法题,于Java毫无关系,第二个题只要看过<<Thinking in Java>>一遍,我想就不只一种设计模式了吧,第三个问题是个最简单的UML图,继承,接口的关系,第四个问题内部类,第五个是个异常,我也做对了是java.lang.ArrayIndexOutOfBoundsException!可是把前面几个题目的答案写出来啊?
      

  3.   

    刚做了第一题请大家指点::
    public class StaticVariable {
      public static void main(String[] args) {
        System.out.println(StaticVariable.setNum(2345432));
      }
      public static boolean setNum(int num) {
        boolean isTrue = false;
        String strNum = String.valueOf(num);
        String strNums[] = new String[strNum.length()];
        if (strNum.length() % 2 != 0) {
          for (int i = 0; i < strNums.length; i++) {
            strNums[i] = strNum.substring(i, i + 1);
            System.out.println("strNums[i]=" + strNums[i]);
          }
          int j = 0;
          for (int i = 0; i < strNums.length - 1 / 2; i++) {
            if (strNums[i].equals(strNums[strNums.length - 1-i])) {
              j++;
            }
            if (j==strNums.length - 1 / 2) {
              isTrue = true;
            }      }
        }
        return isTrue;
      }
    }
      

  4.   

    谁说第5题一定会有异常,你连基本的语法都不会,还说有异常?
    而且居然还肯定地说是 ArrayIndexOutOfBoundsException
      

  5.   

    1)一种实现public class LoopNumber {
      private String s;
      public LoopNumber() {
      }  public LoopNumber(String str) {
        s = str;
      }  public boolean checkNumber() {
        if (s == null) {
          return false;
        }
        char[] cTemp = s.toCharArray();
        char[] c = new char[cTemp.length];
        int j = 0;
        for (int i = cTemp.length - 1; i >= 0; i--) {
          c[j] = cTemp[i];
          j++;
        }
        if (String.valueOf(c).equals(s)) {
          return true;
        }
        return false;
      }  public void setNumber(String str) {
        s = str;
      }  public static void main(String[] args) {
        LoopNumber loopnumber = new LoopNumber();
        loopnumber.setNumber("abccba");
        System.out.println(loopnumber.checkNumber());
      }
    }
      

  6.   

    第二题目。模式很多,工厂,单例模式都是。
    第三题目:
    class Machine {
    }class car
        extends Machine implements Drirable {
      private Wheel wheel0, wheel1, wheel2, wheel3;
      public void tarnlefor() {
      }  public void trunRight() {
      }
    }interface Drirable {
      public void tarnlefor();  public void trunRight();
    }class Wheel {
    }
    简单写写,uml关系在jbuilder直接看
      

  7.   

    题目4:
    好像不全,构造函数没有,估计什么都不会输出。
    题目5:
    没有给处args参数的索引长度,估计也不全。如果数组越界会执行抛异常。编译没问题。以上题目都是基础题目。
      

  8.   

    第一题,给个简单的实现:
    public class StaticVariable
    {
        public static void main(String[] args)
        {
            System.out.println(StaticVariable.setNum0(55));
        }
        
        public static boolean setNum0(int num)
        {
            boolean isTrue = true;        
            String strNum=String.valueOf(num);
            int length=strNum.length();            
            for(int i=0; i<(length/2); i++)
            {
                if(strNum.charAt(i)!=strNum.charAt(length-1-i))
                {
                    isTrue=false;
                    break;
                }
            }        
            return isTrue;
        }