I am preparing for an interview I have in a few days. I was told that I should familiarize myself with CoderPad since that is the collaborator I will be interviewed with. However, I was in the middle of answering a question when I realized I could not read input from System.in using the Scanner class.
For example, running the following:
import java.io.*;
import java.util.*;
/*
* To execute Java, please define "static void main" on a class
* named Solution.
*
* If you need more classes, simply define them inline.
*/
class Solution {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String s = in.next();
System.out.println(s);
}
}
Gives me the message:
Exception in thread "main" java.util.NoSuchElementException
at java.util.Scanner.throwFor(Scanner.java:862)
at java.util.Scanner.next(Scanner.java:1371)
at Solution.main(Solution.java:14)
What's going on here?
Copyright Notice:Content Author:「youngrrrr」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/34277694/using-coderpad-why-do-i-get-a-nosuchelementexception-using-a-scanner-on-system