How do I read a String/int/boolean/etc from the keyboard?
[*] The easiest way is to pick up the source for the 100% pure Java class EasyIn from http://www.afu.com/ (same place as this FAQ). Compile it with your code and use it like this: EasyIn easy = new EasyIn(); int i = easy.readInt(); // gets an int from System.in boolean b = easy.readBoolean(); // gets a boolean from System.in double d = easy.readDouble(); // gets a double from System.in … etc. EasyIn is free, comes with source, and you can do what you like with it, including improve it, and send me back the results. If, instead, you want to “roll your own” code (why?!), in JDK 1.0.2 java.io.DataInputStream in = new java.io.DataInputStream(System.in); String s = in.readLine(); One way in JDK 1.1: java.io.BufferedReader in = new java.io.BufferedReader( new InputStreamReader(System.in)); String s = in.readLine(); Once you have the token in a String, it is easy to parse it into one of the other types, as shown earlier in the FAQ. Yes, it is bone-headed, as it makes the simplest case of ke