Integer input in java

import java.util.Scanner;

public class Main

{

public static Scanner scn=new Scanner(System.in);
public static void main(String args[])
{ int n=scn.nextInt(); }

}

//in the above code why is the compiler showing an error upon executing the code?

hey @bluejay
it shows no errors for me.If u try to print n in the next line it does so.

Integer input in java

Thread link: http://d.cb.lk/t/30102

Hello, i am still encountering a problem in taking integer input in this program. However for the given problem when I am setting the value of n as another integer instead of taking an input I am not encountering any such problems and the output is coming fine. Here is a link to my code .

I just ran the code on netbeans and it is running fine however i am encountering problems when using the codingblocks platform to run it.

@bluejay
i tried submitting your code and it passed both the test cases for me .your code is correct.if u have any other issue ,do let me know

Thanks for the help,

The code submitted successfully however it was still showing runtime error during compilation