Compile Successful but run erro

import java.util.*;
class Main {

public static void merge(int a[],int start,int end)
{
	int[] temp = new int[10];
	for(int i=start;i<=end;i++)
	{
		temp[i] = a[i];
	}
	int mid=(start+end)/2;
	
	int i=start;
	int j=mid+1;
	int k=start;
	
	
	while((i<=mid) && (j<=end))
	{
		if(temp[i]<temp[j])
		{
			a[k] = temp[i];
			i++;
		}
		else
		{
			a[k] = temp[j];
			j++;
		}
		k++;
	
	}
	
	while(i<=mid)
	{
		a[k] = temp[i];
		i++;
		k++;
	}
}
public static void mergeSort(int a[],int start,int end)
{
	if(start<end)
	{
	
	//divide
	int mid=(start+end)/2;
	
	//recursively the array
	mergeSort(a,start,mid);
	mergeSort(a,mid+1,end);
	
	merge(a,start,end);
	}
	
} 

public static void main(String[] args) {
	Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
	int a[] = new int[n];
	int temp[];
    for(int i=0;i<a.length;i++)
    {
        a[i] = sc.nextInt();
    }
	mergeSort(a,0,a.length-1);
	for (int i :a)
	{
		System.out.print(i+" ");
	}
}

}

@Ashi,
Why are you initializing temp as size of 10? Don’t do that. Pass 2 arrays in the merge method. Also return array from mergeSort instead of void.

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.