learner
learner

Reputation: 3120

Online compiler vs native compiler

import java.util.Scanner;
public class Count {
       public static void main(String []args){
       Scanner s=new Scanner(System.in);
       int i=s.nextInt();
       int j=i+1;
       System.out.println(j);
    }

}

It's basic code in java,When i ran it on my own PC it worked fine,The same code i compiled and executed on Online compiler ,it gives some error why??

Exception in thread "main" java.util.NoSuchElementException
    at java.util.Scanner.throwFor(Scanner.java:907)
    at java.util.Scanner.next(Scanner.java:1530)
    at java.util.Scanner.nextInt(Scanner.java:2160)
    at java.util.Scanner.nextInt(Scanner.java:2119)
    at Count.main(Count.java:28) 

Upvotes: 1

Views: 598

Answers (2)

Alexis C.
Alexis C.

Reputation: 93902

There is a field for giving input arguments to STDIN.

During your program you may ask user to input some values in the form of number or strings. Because on the web we can not give interactive option to provide input, so we provided this option to provide all the inputs in one line which will be read by your program using different functions available in your programming language.

enter image description here

Upvotes: 1

Because you did not provide any input for System.in. If you type something, say 2, in the "STDIN Input" box of that online compiler, your program works as expected.

Upvotes: 1

Related Questions