Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 174
  • 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 ?
0
ggmg
Asked:
ggmg
1 Solution
 
fontaineCommented:
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

Example:

DataInputStream in = new DataInputStream(System.in);

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

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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