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

求助:一道面试题,挑出本程序的错误,并改正!
上次去面试的试题,通过接口来实现多次计算两个数字之和,两个数字从键盘输入,然后使用javadoc产生html文档!
代码如下:
/**
  *找程序错误
  *错误1:
  *错误原因:
  *更正:
  *错误n:
  *错误原因:
  *更正:
*/
public   class   Test_Add   {
    static   int   ARRAY_MAX_VALUE   =   10;
    static   int   ADD_XY_COUNT   =   10000;
    int   x,y,z;
    public   static   void   main(String[]   args)   {
        for(int   i=0;i <ADD_XY_COUNT;i++){
            byte[]   number1   =   new   byte[ARRAY_MAX_VALUE];
            byte[]   number2   =   new   byte[ARRAY_MAX_VALUE];
            char[]   c   =   new   char[ARRAY_MAX_VALUE];
            /*   读第一个数   */
       
            System.in.read(number1);
            c   =   (char)number1;
            System.out.println( "number1   =   "   +   c);
            x   =   number1;
            System.out.println( "x   =   "   +   x);
            /*   读第二个数   */
            System.in.read(number2);
            c   =   (char)number2;
            System.out.println( "number2   =   "   +   c);
            y   =   number2;
            System.out.println( "y   =   "   +   y);
            /*   计算X+Y   */
            AddXY   addxy   =   new   AddXY();
            z   =   addxy.AddXY(x,y);
            System.out.println( "   x   +   y   =   "   +   z);
        }
    }
}

public   class   AddXY   implements   TestInterface   {
    int   z;
    public   int   AddXY(int   x,int   y){
        z   =   x   +   y;
        return   z;
    }
}

public   interface   TestInterface   {
    int   AddXY(int   x,int   y);
}


我只挑出了一个错误,它把接口里面写了实现的方法了,其他的没找到!郁闷!

------解决方案--------------------
c = (char)number1;
c = (char)number2;

x = number1;
y = number2;
z = addxy.AddXY(x,y);
------解决方案--------------------
IO操作会产生IOException,这里没有进行处理
------解决方案--------------------
一个文件里不能有多个public的类和接口
------解决方案--------------------
实现类的为什么把z写成字段,、
这个没有什么道理。


整个程序看起不,不像是JAVA。
更像C或者什么的。