Scanner Statements give runtime error

the initialixation statement os scanner runs well on eclipse but here it shows runtime error.

Here is my code:

public static void main(String[] args) {

	Scanner scn = new Scanner(System.in);

	int n = scn.nextInt(); ((ERROR HERE)

	if(n < 0) {
		return;
	}
	int a = getreverse(n);
	System.out.println(a);
	

}


public static int getreverse(int no){
	int rv = 0;
	for(int i = 0 ; no != 0 ; i++) {
		int x  = no % 10;
		no = no / 10;
		rv = (rv*10) + x;
	}
	return rv;
}

And the error is as follows:

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:5)