Insertion sort code

public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[] arr = new int[n];
for (int i = 0; i < arr.length; i++) {
arr[i] = sc.nextInt();
}
Insertionsort(arr);
Display(arr);
}

public static void Insertionsort(int arr[]) {
	for (int counter = 1; counter <= arr.length - 1; counter++) {
		int val = arr[counter];
		int j = counter - 1;
		while (j >= 0 && arr[j] > val) {
			arr[j + 1] = arr[j];
			j--;
		}
		arr[j + 1] = val;
	}
}

public static void Display(int[] arr) {
	for (int i = 0; i < arr.length; i++) {
		System.out.println(arr[i]);
	}
}

code is right but all the test cases are failing

@amangaur078 lemme review it!

@amangaur078 Buddy counter< n not n - 1 as in your code. i have corrected ya code.
If your doubt is resolved mark it resolved and rate full.
Check comments in ya code below:-
import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[] arr = new int[n];
for (int i = 0; i < arr.length; i++) {
arr[i] = sc.nextInt();
}
Insertionsort(arr);
Display(arr);
}

public static void Insertionsort(int arr[]) {
	for (int counter = 1; counter < arr.length; counter++) { // counter < n not n - 1
		int val = arr[counter];
		int j = counter - 1;
		while (j >= 0 && arr[j] > val) {
			arr[j + 1] = arr[j];
			j--;
		}
		arr[j + 1] = val;
	}
}

public static void Display(int[] arr) {
	for (int i = 0; i < arr.length; i++) {
		System.out.print(arr[i] + " ");// same line with space
	}
}

}

@amangaur078 I guess I have already corrected your code bro, any query? check the corrected code above and if no other queries mark it resolved!