Wrong output in Merge Sort

THIS CODE IS SAME AS EXPLAINED IN TUTORIAL. BUT IT IS GIVING WRONG OUTPUT WHILE THE SAME CODE GAVE CORRECT OUTPUT IN TUTORIAL VIDEO. PLEASE CHECK WHERE I AM DOING MISTAKE.

import java.util.*;
public class Main
{
public static int[] mergeTwoSortedArrays(int[] arr1,int[] arr2)
{
int [] merged=new int[arr1.length+arr2.length];
int i=0;
int j=0;
int k=0;
while(i<arr1.length && j<arr2.length)
{
if(arr1[i]<=arr2[j])
{
merged[k]=arr1[i];
i++;
k++;
}
else
{
merged[k]=arr1[j];
j++;
k++;
}
}
if(i==arr1.length)
{
while(j<arr2.length)
{
merged[k]=arr2[j];
j++;
k++;
}
}
if(j==arr2.length)
{
while(i<arr1.length)
{
merged[k]=arr1[i];
i++;
k++;
}
}
return merged;
}

public static int[] mergeSort(int [] arr,int low, int high)
{
    if(low==high)
    {
        int[] br=new int[1];
        br[0]=arr[low];
        return br;
    }
    int mid=(low+high)/2;
    
    int[] fh=mergeSort(arr,low,mid);
    int[] sh=mergeSort(arr,mid+1,high);
    
    int[] merge=mergeTwoSortedArrays(fh,sh);
    
    return merge;
}

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

}

@vinay86048,

https://ide.codingblocks.com/s/228244 corrected code

I have highlighted the incorrect line. Small mistake of merged[k] = arr1[j]; in line 15.

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.