I’m getting an error every time on the ide but not in eclipse.
Can I get a code template for the user input on Java?
hi @lousybrick
here is template to take input for array
n=size of array
a[i]=element at ith index
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scn = new Scanner(System.in);
long n = scn.nextInt();
int a[] = new int[(int) n];
for (int i = 0; i < n; i++) {
a[i] = scn.nextInt();
}
}
}
I’ve tried it and the same error pops up :
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:18)
@lousybrick
you must be using compile and test button put sample input inside the box and then compile and test. or you can directly submit in order to check your code.