hello guys..
i'm new here.
i am trying to do a function that unite two arrays.
this is my code:
arr4 = interSection = gets the intersection of the two arrays.
arr1,arr2 = similar... = reduce the repetition..
i don't see "errors" in the code itself but when i run it.. i get this:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 7 at Even.union(Even.java:64) at Even.main(Even.java:33)
which is this line (64):
arr3[arr1.length+i]=arr2[i-1];
public static int[] union(int[] arr1,int[] arr2) { int[] arr4 = interSection(arr1,arr2); arr1 = Similar(arr1); arr2 = Similar(arr2); int[] arr3 = new int[arr1.length+arr2.length-arr4.length]; for (int i=0;i < arr1.length;i++) arr3[i]=arr1[i]; for (int i=1;i<=arr2.length;i++) arr3[arr1.length+i]=arr2[i-1]; return Similar(arr3); }