Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

How do I read a String/int/boolean/etc from the keyboard?

Boolean int keyboard read String
0
Posted

How do I read a String/int/boolean/etc from the keyboard?

0

[*] 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

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123