• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 175
  • Last Modified:

Read as integer...

OK, I want to have an interface to read a keyboard input to be understood as integer or double, to perform some calculation upon that number. What's the easiest way to do it ?
1 Solution
System.in provides you with an InputStream to read data from the standard input stream, i.e. the keyboard. As you need a higher level of abstraction, build a DataInputStream upon it and use its readInt(), readByte(), etc., methods


DataInputStream in = new DataInputStream(System.in);

try {
int anInt = in.readInt();
double aDouble = in.readDouble();
} catch (IOException e) {
ggmgAuthor Commented:
Thanks a lot...
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now