When compiling it shows right answer but on submitting it shows compilation error

import java.util.*;
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<arr.length; i++) {
arr[i] = scn.nextInt();
}
insertion(n, arr);
}

public static void insertion(int n, int a[]) {
	for (int i = 0; i < a.length; i++) {
		int temp = a[i];
		int j = i - 1;
		while (j >= 0 && a[j] > temp) {
			a[j + 1] = a[j];
			j--;
		}
		a[j + 1] = temp;
	}
	for (int i = 0; i < a.length; i++) {
		System.out.println(a[i]);
	}
}

}

This is happening because you should take input of n using scanner.nextLine() and not scanner.nextInt() since it takes space delimited input.

pls explain because it is not working with that

use int n = Integer.parseInt(scanner.nextLine());

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.

still not working it is showing error , want to know where this is taught in the videos?

Did you try using scanner.nextLine() like I told you ? If you did, please post your solution here.