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

public static void main(String args[]) {
    int[] a = {1,1,1,1,1};
    int[] b = {2,2,2,2,2};
    System.out.println(Arrays.toString(S2020Mini2.interleave(a, b)));

I am getting an ArrayIndexOutOfBoundsException error and I would appreciate some help in solving this issue. Thank you for your help.

Kyodi
  • 31
  • 8
  • Time to run your program inside of your favorite IDE's debugger to see exactly why the exception is occurring. – Hovercraft Full Of Eels Mar 20 '20 at 01:46
  • You need to put in the entire code. Leaving off a few lines just makes it difficult for those of us willing to try to help you debug it. This means the import statements and the name of the classesl – NomadMaker Mar 20 '20 at 02:31

0 Answers0