Getting an exception and why?

Code:

package recursion;

public class Merge {

public static void main(String[] args) {

	int[] arr = {50, 5, -10, 80, 120, 0 };
	int[] res = MergeSort(arr, 0, arr.length-1);
	// print the array
	for (int i = 0; i < res.length; i++) {
		System.out.print(res[i] + " ");
	}
}

public static int[] MergeTwoSortedArrays(int[] arr1, int[] arr2) {
	int i = 0, j = 0, k = 0;
	int[] merged = new int[arr1.length + arr2.length];
	while (i < arr1.length && j < arr1.length) {
		if (arr1[i] <= arr2[j]) {
			merged[k] = arr1[i];
			i++;
			k++;
		} else {
			merged[k] = arr2[j];
			j++;
			k++;
		}
	}

	if (i == arr1.length) {
		merged[k] = arr2[j];
		j++;
		k++;
	}

	if (j == arr2.length) {
		merged[k] = arr1[i];
		i++;
		k++;
	}
	return merged;
}

public static int[] MergeSort(int[] arr, int lo, int hi) {
	if (lo == hi) {
		int[] br = new int[1];
		br[0] = arr[lo];
		return br;
	}

	int mid = (lo + hi) / 2;
	int[] fh = MergeSort(arr, lo, mid);
	int[] sh = MergeSort(arr, mid + 1, hi);

	 return MergeTwoSortedArrays(fh, sh);

	//return merge;

}

}

Hi @bharath_gopishetti
Can you Please Share this code by saving it on coding blocks ide So that I can help you better!

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.