private static int[] range(int l, int h, int s) {
        int[] ints = new int[(h - l) % s];
        for (int x = l; x < h; x += s)
            ints[(x - l) / s] = x;
        return ints;
    }报错:java.lang.ArrayIndexOutOfBoundsException: 0

解决方案 »

  1.   

    ints[(x - l) / s] 这个的数组的值超过范围,就是(x - l) / s可能大于(h - l) % s
      

  2.   

    你这是什么公式?这样写最容易出bug了。int a = (h - l) % s;
       int[] ints = new int[a];
            for (int x = l; x < h; x += s){
             int b = (x - l) / s;
             if(b < a){
                ints[b] = x;
             }
      

  3.   

    int[] ints = new int[(h - l) % s
    需要这样吗