无法递归调用我的算法

时间:2015-04-01 16:47:21

标签: java recursion

我正在编写一个分而治之的算法,但我在递归调用它时遇到了麻烦。它说它找不到符号方法Multiply和变量m,e,m

public class Multiply {

    private static int randomInt(int size) {
        int maxval = (1 << size) - 1;
        return (int)(Math.random()*maxval);
    }



    public static int[] naive(int size, int x, int y) {
      int[] result = new int[3];

      if (size == 1) {
        result[0] = x*y;
      }

      else {
        int m = size/2;
        int a = x/2;
        int b = x % (int)Math.pow(2,m);
        int c = y / (int)Math.pow(2,m);
        int d = y % (int)Math.pow(2,m);
        int e = Multiply(a,c,m);
        int f = Multiply(b,d,m);
        int g = Multiply(b,c,m);
        int h = Multiply(a,d,m);
      }
        return ((int)Math.pow(2,2*m)*e) + ((int)Math.pow(2,m)*(g+h)) + f; 

    }

1 个答案:

答案 0 :(得分:1)

尝试使用Multiply.naive(x,y,z)代替Multiply(x,y,z)