How to read an input line in Java
import java.io.*;
public class InputExample {
// This creates an object from which you can read input lines.
// It is declared static just so it can be used from "main".
static BufferedReader reader =
new BufferedReader(new InputStreamReader(System.in));
// This reads an input line (without the \n), catching any exceptions.
// It reads a line of input, or returns null if there is no more input.
// It is static just so it can be used from "main".
public static String readLineOrNull() {
try {
return reader.readLine();
}
catch (IOException e) {
return null;
}
}
public static void main(String args[]) {
String line = null;
while ((line = readLineOrNull()) != null)
System.out.println("Got: >>" + line + "<<");
}
}