1
public static void main(String args[])
    {
        int[] a = {0, 1, 2, 3};
        int[] b = {100, 101, 102, 103, 104, 105};
        System.out.print(shuffleArrays(a, b));
    }

    public static int[] shuffleArrays(int[] a, int[] b)
    {
        int[] c = new int[a.length+b.length];
        for (int i=0; i<b.length-1; i++)
        {
            if (i<a.length-1 && i<b.length-1)
                c[i] = c[i] + (a[i] + b[i]);
            else if (i>=a.length-1)
                c[i] = c[i] + b[i];
            else if (i>=b.length-1)
                c[i] = c[i] + a[i];
        }

        return c;
    }

This is giving me an output of "[I@1837b90c". No idea why this is happening. Am I calling on the method incorrectly?

user2770254
  • 89
  • 1
  • 7

2 Answers2

3

You're printing the reference to the array that is returned by shuffleArrays. This does not automatically print out the contents of the array, but instead prints the array reference. You would want to do something like the following:

System.out.print(Arrays.toString(shuffleArrays(a, b)))
Mike Bockus
  • 2,079
  • 17
  • 23
0

Also you have the wrong method, this one is working fine :

public static void main(String args[]) {
    int[] a = {0, 1, 2, 3};
    int[] b = {100, 101, 102, 103, 104, 105};
    //c[] = {0, 100, 1, 101, 2, 102, 3, 103, 104, 105}
    System.out.print(Arrays.toString(shuffleArrays(a, b)));
}

public static int[] shuffleArrays(int[] a, int[] b) {
       public static int[] shuffleArrays(int[] a, int[] b) {
    int[] c = new int[a.length + b.length];
    int[] smaller;
    int[] bigger;
    if (a.length < b.length){
        smaller = a;
        bigger = b;
    } else {
        smaller = b;
        bigger = a;
    }

    for (int i = 0; i < smaller.length; i++) {
        c[i*2] = smaller[i];
        c[i*2+1] = bigger[i];
    }
    for (int i = 0; i < bigger.length - smaller.length; i++) {
        c[smaller.length*2+i] = bigger[smaller.length+i];
    }

    return c;
}
libik
  • 22,239
  • 9
  • 44
  • 87