Solved

Read as integer...

Posted on 1998-05-06
2
168 Views
Last Modified: 2010-04-16
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
Comment
Question by:ggmg
2 Comments
 
LVL 5

Accepted Solution

by:
fontaine earned 50 total points
ID: 1220597
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
 

Author Comment

by:ggmg
ID: 1220598
Thanks a lot...
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now