What is wrong in this code?

public static void main(String[] args) {

	Scanner scn=new Scanner(System.in);
	int n=scn.nextInt();
	int [] arr=new int[n];
	for (int i=0;i<=n;i++) {
		arr[i]=scn.nextInt();
		
	}
	Quicksort(arr,0,arr.length-1);
	for(int val : arr) {
		System.out.println(val+" ");
	}
	

}
public static void Quicksort(int [] arr,int lo,int hi) {
	if (lo>=hi) {
		return;
	}
	int mid=(lo+hi)/2;
	int pivot=arr[mid];
	int left=lo;
	int right=hi;
	while (left<=right) {
		while (arr[left]<pivot) {
			left++;
		}
		while(arr[right]>pivot) {
			right--;
		}
		if (left<=right) {
			int temp=arr[left];
			arr[left]=arr[right];
			arr[right]=temp;
			
			left++;
			right--;
		}
	}
	Quicksort(arr,lo,right);        

	Quicksort(arr,left,hi);
	
}

Hey @harsh.hj
logic is just a change
for (int i=0;i<n;i++) {
arr[i]=scn.nextInt();

}

correct code :

import java.util.Scanner;

public class Main {
public static void main(String[] args) {
Scanner scn = new Scanner(System.in);
int n = scn.nextInt();
int[] arr = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = scn.nextInt();
}
Quicksort(arr, 0, arr.length - 1);
for (int val : arr) {
System.out.print(val + " ");
}
}

public static void Quicksort(int[] arr, int lo, int hi) {
	if (lo >= hi) {
		return;
	}
	int mid = (lo + hi) / 2;
	int pivot = arr[mid];
	int left = lo;
	int right = hi;
	while (left <= right) {
		while (arr[left] < pivot) {
			left++;
		}
		while (arr[right] > pivot) {
			right--;
		}
		if (left <= right) {
			int temp = arr[left];
			arr[left] = arr[right];
			arr[right] = temp;
			left++;
			right--;
		}
	}
	Quicksort(arr, lo, right);
	Quicksort(arr, left, hi);
}

}