Reading input (stdin)
Read what you type in the IDE's Input tab with Scanner or BufferedReader.
Runs in Zerethon IDE · Java 25
Official Java documentation ↗
A run cannot ask questions while it runs: type the input in the Input tab before pressing Run.
Main.java
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String name = in.nextLine();
int a = in.nextInt();
int b = in.nextInt();
System.out.println("Hello, " + name + "! " + a + " + " + b + " = " + (a + b));
}
}
Input (stdin)
Ada 3 4
Output
Hello, Ada! 3 + 4 = 7
Main.java
import java.io.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
int total = 0;
String line;
while ((line = in.readLine()) != null) {
if (!line.isBlank()) total += Integer.parseInt(line.trim());
}
System.out.println("total: " + total);
}
}
Input (stdin)
5 10 15
Output
total: 30
BufferedReader is faster for large input; readLine() returns null at the end.
Watch out: After nextInt(), the rest of that line is still waiting — call nextLine() once before reading the next full line. Reading past the end throws NoSuchElementException.