Scanner class error

I am getting the folllowing error. pls help

Exception in thread “main” java.util.NoSuchElementException
at java.util.Scanner.throwFor(Scanner.java:862)
at java.util.Scanner.next(Scanner.java:1485)
at java.util.Scanner.nextInt(Scanner.java:2117)
at java.util.Scanner.nextInt(Scanner.java:2076)
at Main.main(Main.java:16

code:
import java.util.*;
public class Main {

public static boolean checkIsSorted(int []arr, int si){
	if(si == arr.length-1)
		return true;
	if(arr[si] > arr[si+1])
		return false;
return (checkIsSorted(arr, si+1));	
}

public static void main(String args[]) {
    // Your Code Here
	
	Scanner sc = new Scanner(System.in);
	int a = sc.nextInt();
	int []arr = new int[a];
	for(int i=0; i<a; i++){
		arr[i] = sc.nextInt();
	}
	System.out.print(checkIsSorted(arr,0));
}

}

This exception come when you don’t provide the proper no of inputs.

Your code is correct. Just check if you are providing correct no of inputs from stdin.
for eg. if you need to provide array of size 7, then input will be
7 33 34 35 78 98 556 557

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.