Java Compiler with Scanner Input
Most online Java compilers ignore stdin. Ours doesn't. Drop your Scanner code in, paste your input, and run it just like on a local JDK. Java 17 compatible.
Run Java Compiler with Scanner Input examples in the Java compiler
Examples included
Practical tips
- After nextInt(), call sc.nextLine() to consume the leftover newline before reading text.
- For competitive programming and large inputs, prefer BufferedReader over Scanner — it's 5–10x faster.
- Each line of stdin should match what your program calls. Multiple nextInt() can read from the same line if separated by spaces.
- Use sc.hasNextInt() to safely loop until end of input.
Common questions
How do I provide input to a Java program online?
Type or paste your input into the "Custom Input (stdin)" panel below the editor before clicking Run.
Why does nextLine() skip my input?
It picks up the leftover newline from a previous nextInt(). Add an extra sc.nextLine() to consume it.
What's the difference between Scanner and BufferedReader?
Scanner is friendlier; BufferedReader is faster. For 100k+ inputs, BufferedReader is the right choice.
Practice related Java exercises · Browse Java programs with output