Array out of bound exception

public static int[] mergeSortedArray(int a[] ,int b[] ) {
int ml = a.length + b.length;
int [] merged = new int[ml];
int i=0,j=0,k=0;
while(i<a.length &&j<b.length) {
if(a[i]<=b[j]) {
merged[k]= a[i];
i++;
k++;
}
else {
merged[k] = a[j];
j++;
k++;
}
}

		while(j<b.length) {
		/	merged[k] = a[j];
			j++;
			k++;
		
	}
	
		while(i<a.length) {
			merged[k] = a[i];
			i++;
			k++;
		}
	

	return merged;
	
}

I am receiving a array out of bound on the / marked line

That’s because you are accessing array a at places where you are supposed to access b. merged[k] = b[j] it should be and not merged[k] = a[j]

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.