int[] arrFirst = {1,6}; int[] arrSecond = {4}; public void addition() { int[] arr = new int[this.arrFirst.length+this.arrSecond.length]; for (int i = 0, j = 0, m = 0; i != arr.length; i++) { if (this.arrFirst[m] < this.arrSecond[j]) { arr[i] = this.arrFirst[m]; if (m != this.arrFirst.length){ m++; } System.out.println(arr[i]); } else { arr[i] = this.arrSecond[j]; if (j < this.arrSecond.length){ j++; } System.out.println(arr[i]); } } The problem is that I have ArrayIndexOutOfBoundsException: 1 when checking this.arrFirst[m] < this.arrSecond[j] at the third iteration, although j that follows this is set to if (j != this.arrSecond.length) and increment at Access to valley -1 array should not.
Tell me where I screwed up? Something is not like I will not find (((
malready equal tolength- then on the line above you will get an exception, which you will get now :) - Grundy